I need to build 3 double linked lists of numbers. It is a part of a larger program I write, which will compare elemnts of those lists. After searching thoroughly archive could not find it. This is what I wrote, but I know it's a false.
please help!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct NodeStruct Node;
typedef Node *NodePointer;
struct NodeStruct{
int value;
NodePointer next;
NodePointer previous;
};
NodePointer newNode (NodePointer prevNode, int value)
{
NodePointer newNode;
newNode=(NodePointer)malloc (sizeof(Node));
newNode->next=NULL;
newNode->previous=prevNode;
prevNode->next= newNode;
newNode->value= value;
return newNode;
}
NodePointer CreateList (NodePointer head)
{
NodePointer current;
current = head;
current->previous=NULL;
current->next=NULL;
return current;
}
void main ()
{
Node head1, head2, head3;
NodePointer current1, current2, current3;
int count=0;
/*creating emtpy list no. 1*/
current1=CreateList(&head1);
/*populating list 1*/
puts ("enter an integer:");
scanf("%d",current1->value);
while(current1->value!=0)
{
puts ("enter an integer:");
scanf("%d",¤t1->value);
current1->next=newNode(current1, current1->value);
current1 = current1->next;
}
/*creating emtpy list no. 2*/
current2=CreateList(&head2);
/*populating list 2*/
puts ("enter an integer:");
scanf("%d",current2->value);
while(current2->value!=0)
{
puts ("enter an integer:");
scanf("%d",¤t2->value);
current2->next=newNode(current2, current2->value);
current2 = current2->next;
}
/*creating emtpy list no. 3*/
current3=CreateList(&head3);
/*populating list 3*/
puts ("enter an integer:");
scanf("%d",current3->value);
while(current3->value!=0)
{
puts ("enter an integer:");
scanf("%d",¤t3->value);
current3->next=newNode(current3, current3->value);
current3 = current3->next;
}
}