void place(NODEPTR *plist, int x) { NODEPTR p, q = NULL; for (p = *plist; p != NULL; p = p->next) q = p; /* at this point, a node containing x must be inserted */ insafter(q, x); }
/* Drier program to test above function*/ int main() { /* Start with the empty list */ struct node* head = NULL; int ele; printf("Enter the element\n"); while(scanf("%d",&ele)!=EOF){ insafter(&head, ele); } printList(head); reverse(&head); printf("\n Reversed Linked list by non rerusive \n"); printList(head); printf("\nReverse Linked list by recursive\n"); recursiveReverse(&head); printList(head); getchar(); }
void insert(nodeptr list, int n) { int i=1; char x; for(i=1;i<=n;i++) { printf("Enter the item to be inserted at node %d ",i); x=getche(); printf("\n"); if(i==1) insbgn(&list,x); else if(i==n) insend(&list,x); else { nodeptr p,q; p=list; q->next=p; insafter(q,x); } } printf("Nodes inserted with the given info\n"); }