I need help figuring out the algorithm to insert into an array of structs. I'm not allowed to use pointer since next will be pointing to the next node.
Code:
struct Inode { int item;int next; };
Inode node[10];
So, I have an array of 10 struct.
I initialize all the next to 1 to 9, with the last next to -1.
Code:
ptr = free; free = node[free].next;
if (head == -1) { node[ptr].item = newItem;
node[ptr].next = -1; head = 0;}
That was for the first insertion.
so, I insert it into a free node, and set next to -1 to indicate that it is the end of the list.
I'm having trouble with inserting the 2nd item.
I need to change the next of the previous node to 1 instead of -1, and i'll be setting the next value to -1 on the 2nd node.
Basically, I would want to linked 'item' in a sorted order.