Dear Programmers,
i have a problem with linked lists. I have an character array. This will look like this:
array[0] = 1
array[1] = 4
array[2] = 8
Now, i will make an structure:
Now, i would like to make a linked list, which looks likeCode:typedef struct node node;
struct node{
char value;
node* p;
};
node1->value= '1'
node2->value= '4'
node3->value= 8
Now, i have it like this:
But it will look better if i can make a loop of it (e.g. because if i have a larger array for example). But how can i do that?Code:node *temp;
node *temp1=NULL;
node *temp2=NULL;
temp = (node*)malloc(sizeof(node));
temp->value = p[0];
temp->next = temp1;
temp1 = (node*)malloc(sizeof(node));
temp1->value = p[1];
temp1->next = temp2;
temp2 = (node*)malloc(sizeof(node));
temp2->value = p[2];
temp2->next = NULL;
Best Peter