How do you implement a linked list without using dynamic memory .....
Software QA/Tests Interview Questions from Microsoft
(Continued from previous question...)
How do you implement a linked list without using dynamic memory .....
Question:
How do you implement a linked list without using dynamic memory allocation? So basically you need to use an array as a linked list.
maybe an answer:
head = -1, count = 0;
insert(int array, int node)
{
array[count]=node;
if(count == 0)
head=array[count];
count++;
}
int delete(int array, int node)
{
if(count==0)
retuen -1;
int n=0, i=0;
while(array[n]!=node)
n++;
for(i=count-n-1; i<count-1; i++)
array[i] = array[i+1];
count--;
return 1;
}
(Continued on next question...)
Other Interview Questions
|