## rithish 13

hello can any one give a easiest and understandble link or video tutorial for cursor implementation of linked list very hard to understand please suggest a good link and understandable

## deceptikon 1,790

The simplest cursor linked list would be an array of nodes where the "next" pointer is actually just an index to another element in the array. The linked list concept is the same, all that changes is how you link to other nodes.

## deceptikon 1,790

Pardon my confusion, but is it really too difficult to reason about with nothing more than an understanding of linked lists and a functioning brain? You're going to encounter situations where there's not a web page to teach you everything about a subject, and your only recourse is to figure it out through experimentation.

Now, I could certainly do a google search for you and post some links here, but I think it might be better to force you to be inventive while things are still relatively easy. If you don't have practice in real problem solving (and not just regurgitating what you've read in a book or on a website), you'll be massively overwhelmed when the tasks become truly complex.

commented: But if I google it, how will I know which link will be understandable??? 8-P +14

## rithish 13

ok i know linked list to implement in structures and arrays but cursor is quite difficult for me to understand.i dont know how an array can have next link ????bit confusing for me

## rithish 13

please explain or give me some link without anything i can't do it how its possible ???i searched even in google most of links r confusing and some r wrong links showing linked list

## deceptikon 1,790

ok i know linked list to implement in structures and arrays but cursor is quite difficult for me to understand.i dont know how an array can have next link ????

Okay, it sounds like your concept of links is focused too much on pointers. A link is nothing more than some way to get to the next node. The most common way to implement that is directly with a pointer, but you can also do it with an array index. Look, same concept, different method of implementation:

``````#include <stdio.h>

struct node {
int data;
int next;
};

static struct node freelist[100];
static int next = 0;

int main(void)
{
int i;

for (i = 0; i < 10; ++i) {
freelist[next].data = i;
freelist[next].next = next++ - 1;
}

for (i = next - 1; i >= 0; i = freelist[i].next)
printf("%d\n", freelist[i].data);

return 0;
}
``````

That's all there is to it.

## rithish 13

`````` for (i = 0; i < 10; ++i) {
freelist[next].data = i;
freelist[next].next = next++ - 1;
}
``````

this line of code is used for memory allocation right???

``````freelist[0].data=0;
freelist[0].next=0;
freelist[1].data=1;
free[1].next=1;
``````

the above specified lines of code i tried it in a paper work but here the 1st link should go to 2 right i mean like this freelist[1].next=2.but it goes like this in actual freelist[0].next=0;

## deceptikon 1,790

this line of code is used for memory allocation right???

The memory is already allocated (all nodes are stored in the global `freelist` array). Those lines of code are extracting an unused node and attaching it to the cursor list. Note that this is a very simple way of using indexes as links, it's not really well suited for a serious implementation. But it's adequate for expanding one's mind as to the possibilities beyond pointers.

the above specified lines of code i tried it in a paper work but here the 1st link should go to 2 right

The important thing to keep in mind is that the order of nodes in `freelist` is completely independent of the values of each node's `next` member. You could set it up like this and it'll work just fine:

``````#include <stdio.h>

struct node {
int data;
int next;
};

int main(void)
{
struct node freelist[100];
int i;

freelist[56].data = 0;
freelist[56].next = 11;
freelist[11].data = 1;
freelist[11].next = 34;
freelist[34].data = 2;
freelist[34].next = 72;
freelist[72].data = 3;
freelist[72].next = -1;

for (i = 56; i >= 0; i = freelist[i].next)
printf("%d\n", freelist[i].data);

return 0;
}
``````

It doesn't matter what the value of `next` is as long as it refers to the logical next node in the list.

## rithish 13

but in normal linked list we input the values from user for example like scanf("%d",t->data); but here everything is static.so here we have to allocate everything before entering data???so this is a static allocation right???

## deceptikon 1,790

but in normal linked list we input the values from user for example like scanf("%d",t->data);

You can do that here too, I just chose not to because it would complicate the code and obscure the actual logic of the list.

but here everything is static

I think you mean "hardcoded". static has very specific meanings in C, so I'd recommend not using that word for something that isn't one of those.

so here we have to allocate everything before entering data???

You always have to allocate space before entering data. While an array is used here, there's nothing stopping you from using a dynamic array that's resized as new nodes are needed. Remember, my example is just an example, and a very simple one at that. Use your imagination for other variations of the cursor list concept.

## rithish 13

in my book the code initialization looks like dis

``````int i;
for(i=0;i<n;i++)
{