top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Implement link list without pointer in C Language ??

+5 votes
757 views

Implement link list without pointer ??

posted Nov 17, 2013 by Anuj Yadav

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
typedef struct item {
    type data;
    struct item next;
} Item;

and now the C compiler will go to try to figure out how large Item is. But since next is embedded right in Item, it'll end up with an equation like this

size-of-Item = size-of-type + size-of-Item

You end up with an infinitely large data structure that would use an infinite amount of memory, and that of course can't work.

answer Nov 18, 2013 by Satyabrata Mahapatra
how you will allocate/assign memory for this ?
+1 vote

I believe the best way to implement the link list without pointer is to use array.

struct node 
{ 
   type data;
   int    index;
};

struct node linklist[MAX_SIZE];

Here index represent the index within the array.

Drawback:
1. All the index may not be used which means a wastage of memory.
2. LinkList can not grow beyond the MAX_SIZE

answer Nov 18, 2013 by Salil Agrawal
...