Simle c code to create link list

Here i have written the best code to start makin link list so enjoy the code.......
struct node{ int Data,struct *NextNodeAddress};//defined structure of node
//now we will make a golobal head node
struct node *Head = NULL;
//now going to create node
strct node * makenode(int data)
{
struct node *TempNode = (struct node *)malloc(sizeof(struct node));//memory created
TempNode->Data = data;
TempNode->NextNodeAddress = NULL;
return TempNode;
}
//used malloc function to create node and use type cast create node type data
//create the list
void CreateList(struct ** node Head,struct node *NodeToAdd)
{
struct node *TempNode =&Head;
if(&Head == NULL)
{ &Head = NodeToAdd;
TempNode = NodeToAdd;}
else{ TempNode->NextNodeAddress = NodeToAdd;
TempNode = NodeTOAdd;
}
}
inside the main functionjst put the following call in loop to create olist dynamicallly'
main()
{
CreateList(&Head,makenode(1));
CreateList(&Head,makenode(2));
CreateList(&Head,makenode(3));
CreateList(&Head,makenode(4));
}
the above code is the simplest code to learn and create the link list

Comments

Popular posts from this blog

XML Programming using IXMLDOMDOCUMENT in vc++

Get correct OS version on win 8.1 without using GetVesionEx API (deprecated )