Data structure First: Create a linear list and traverse
1#include <stdio.h>2#include <stdlib.h>3 4 //defining a list element structure5typedefstructNode6 {7 intname;8 structNode *_next;9 }pnode;Ten One //Create a linear list APnode *createstudnetlist () { - inti; -Pnode *head,*temp,*tail; theHead=tail=NULL; -printf"Enter 3 char\n"); - for(i=0;i<3; i++) - { +temp= (pnode*)malloc(sizeof(Pnode)); -scanf"%d",&temp->name); + if(head==NULL) { AHead=tail=temp; at } - Else - { -tail->_next=temp; -Tail=temp; -tail->_next=NULL; in } - } to returnhead; + } - the //traversing a linked list * voidPrintlist (Pnode *m) $ {Panax NotoginsengPnode *p=m; -printf"The list is:\n"); the while(p->_next!=NULL) + { Aprintf"%d\n",p->name); theP=p->_next; + } -printf"%d\n",p->name); $ } $ - voidMain () { -Pnode *list=createstudnetlist (); the printlist (list); -System"Pause");Wuyi}
Data structure (i) Creating and traversing lists