I have this code perfectly working for representation of one way linked list in C..
using test dummy constants in main()
I formed the list
13 -> 23 -> 24 -> 45 -> 34 -> 45
At few points on this code..I am still unable to figure out the use of function pointer
Take the example *Getnode()...(it returns a node if memory alloction for a node is possible)
and please explain to me what is the purpose of '*' in getnode()
Code:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#define NULL 0
typedef struct node
{
int DATA;
struct node *LINK;
}NODE;
NODE *Getnode();
NODE *InsertAtEnd(NODE *,int);
void Display(NODE *);
NODE *Getnode()
{
NODE *New;
New=(NODE *)malloc(sizeof(NODE));
New->LINK=NULL;
return New;
}
NODE *InsertAtEnd(NODE *START,int x)
{
NODE *New;
NODE *Copy;
Copy=START;
New=Getnode();
if(New==NULL)
{
printf("MEMORY ALLOCATION ERROR\n");
}
New->DATA=x;
if(START==NULL)
{
Copy=New;
}
while(START->LINK!=NULL)
{
START=START->LINK;
}
START->LINK=New;
return Copy;
}
void Display(NODE *START)
{
while(START!=NULL)
{
printf("%d ",START->DATA);
START=START->LINK;
}
}
int main()
{
NODE *S=NULL;
clrscr();
S=InsertAtEnd(S,13);
S=InsertAtEnd(S,23);
S=InsertAtEnd(S,34);
S=InsertAtEnd(S,45);
S=InsertAtEnd(S,34);
S=InsertAtEnd(S,45);
Display(S);
getch();
return 0;
}
//END