diff --git a/LinkedList/Create_list.cpp b/LinkedList/Create_list.cpp index 1fd77b9..b693005 100644 --- a/LinkedList/Create_list.cpp +++ b/LinkedList/Create_list.cpp @@ -1,11 +1,19 @@ +//.......................................This program is used to define Link least using structure......................................................... #include using namespace std; + +//.......................node is user define datatype , which contain two elements in it.................................... +// 1) integer data (its own data) +// 2) node type pointer, used to store address of next node struct node{ int data; node *next; }; -void printList(node *n){ -while(n!=NULL){ + +// printList() function is used to print data stores in all nodes +void printList(node *n) +{ + while(n!=NULL){ cout<data<next; @@ -13,17 +21,24 @@ while(n!=NULL){ } int main(){ + + // defining three pointers of type node, use to point elements of node node *head=new node(); node *second=new node(); node *third=new node(); + head->data=5; + // next pointer of head node stores addresscof second node head->next=second; second->data=9; + // next pointer of second node stores address of third node second->next=third; third->data=7; + // next pointer of third node stores NULL value in it, because there is no next node third->next=NULL; - + + // calling to print data of all nodes, using only head node printList(head); -} \ No newline at end of file +}