/* delete the specific node by passing that address { struct Node* temp = node_ptr->next; node_ptr->data = temp->data; node_ptr->next = temp->next; free(temp); }*/ int main() { struct Node* first; struct Node* second; struct Node* third; first = (struct Node*)malloc(sizeof(struct Node*)); second = (struct Node*)malloc(sizeof(struct Node*)); third = (struct Node*)malloc(sizeof(struct Node*)); first -> data = 1; first -> next = second; second -> data = 2; second -> next = third; third -> data = 3; third -> next = NULL; addatbeg(&first,10); append(&first,100); insertafter(&first,2,80); del(&first,3); printlist(first); return 0; }
void main() { struct node *p; p=NULL; int ele,ch,key=0; while(!0) { system("cls"); printf("1. Insert At Front\n2. Insert to Left\n3. Delete Node\n4. Display\n5. Exit\n\nEnter Choice : "); scanf("%d",&ch); switch(ch) { case 1:printf("\nEnter Element To Insert : "); scanf("%d",&ele); p=addatbeg(p,ele); break; case 2:printf("\nEnter Element To Insert : "); scanf("%d",&ele); printf("\nEnter Key To Search On : "); scanf("%d",&key); p=addleft(p,ele,key); break; case 3:p=del(p); break; case 4:display(p); break; case 5:exit(0); break; default:printf("\nInvalid Selection"); } } }
main() { int choice,n,m,po,i; last=NULL; while(1) { printf("1.Create List\n"); printf("2.Add at begining\n"); printf("3.Add after \n"); printf("4.Delete\n"); printf("5.Display\n"); printf("6.Quit\n"); printf("Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("How many nodes you want : "); scanf("%d",&n); for(i=0; i < n;i++) { printf("Enter the element : "); scanf("%d",&m); create_list(m); } break; case 2: printf("Enter the element : "); scanf("%d",&m); addatbeg(m); break; case 3: printf("Enter the element : "); scanf("%d",&m); printf("Enter the position after which this element is inserted : "); scanf("%d",&po); addafter(m,po); break; case 4: if(last == NULL) { printf("List underflow\n"); continue; } printf("Enter the number for deletion : "); scanf("%d",&m); del(m); break; case 5: display(); break; case 6: exit(); default: printf("Wrong choice\n"); }/*End of switch*/ }/*End of while*/ }/*End of main()*/
int main() { struct node *front, *rear; front=rear=NULL; addatend(&front, &rear, 10); //10 qdisplay(front); addatbeg(&front, &rear, 20); //20 10 qdisplay(front); addatbeg(&front, &rear, 30); //30 20 10 qdisplay(front); addatend(&front, &rear, 5); //30 20 10 5 qdisplay(front); delbeg(&front, &rear); //20 10 5 qdisplay(front); delend(&front, &rear); //20 10 qdisplay(front); getch(); }
struct node *CreateReverse(struct node *start) { struct node *startRev=NULL; struct node *p=start; while(p!=NULL) { startRev = addatbeg(startRev,p->info); p=p->link; } return startRev; }/*End of CreateReverse()*/
void EvenOdd(struct node *start1,struct node **start2,struct node **start3 ) { struct node *p1=start1, *p2=*start2, *p3=*start3; while(p1!=NULL) { if( (p1->info)%2 != 0 ) { if(*start2==NULL) *start2 = addatbeg(*start2,p1->info); else *start2 = addatend(*start2,p1->info); } else { if(*start3==NULL) *start3 = addatbeg(*start3,p1->info); else *start3 = addatend(*start3,p1->info); } p1=p1->link; } }/*End of EvenOdd()*/
struct node *create_list(struct node *start) { int i,n,data; printf("Enter the number of nodes : "); scanf("%d",&n); start=NULL; printf("Enter the element to be inserted : "); scanf("%d",&data); start=addatbeg(start,data); for(i=2;i<=n;i++) { printf("Enter the element to be inserted : "); scanf("%d",&data); start=addatend(start,data); } return start; }/*End of create_list()*/
void main() { struct node *p; p=NULL; int ch,ele,pos=0; while(true) { system("cls"); printf("1. Insert At Front\n2. Display\n3. Exit\n4. Add At Back\n5. Add At Pos\n6. Search n Update\n7. Delete\n\nEnter Choice : "); scanf("%d",&ch); switch(ch) { case 1: printf("Enter Record To Insert : "); addatbeg(&p); break; case 2: display(p); break; case 3: exit(0); break; case 4: printf("Enter Record To Insert : "); append(&p); break; case 5: printf("Enter Position To Insert At : "); scanf("%d",&pos); addatpos(&p,pos); break; case 6: search(&p); break; case 7: del(&p); break; default: printf("Invalid Selection"); } getch(); } }
struct node * addleft(struct node *q,int ele,int key) { struct node *r,*temp; int flag=0; temp=getnode(); r=q; if(r==NULL) { printf("\nEmpty List"); return q; } if(q->item==key) { q=addatbeg(q,ele); return q; } while(r->r!=NULL) { if(r->item==key) { temp->item=ele; temp->r=r; temp->l=r->l; r->l->r=temp; r->l=temp; flag=1; } r=r->r; } if((r->r==NULL)&&(r->item==key)) { temp->item=ele; temp->r=r; temp->l=r->l; r->l->r=temp; r->l=temp; return q; } if(!flag) printf("\nKey Not Found In List"); return q; }
void append(struct node **q) { struct node *temp,*r; if(*q==NULL) { addatbeg(q); return; } else { temp=*q; while(temp->link !=NULL) temp=temp->link; r=getnode(); getdata(r); r->link=NULL; temp->link=r; } }
void main() { struct node *root; int ans, num; root = NULL; ans = 0; while(ans!=3) { system("cls"); display(root); printf("\n\t 1. Create"); printf("\n\t 2. Append"); printf("\n\t 3. Exit"); printf("\n\t 4. Add At begining"); printf("\n\t Enter Choice : "); scanf("%d",&ans); switch(ans) { case 1: printf("\n\t Enter Element : "); scanf("%d",&num); create(&root, num); break; case 2: printf("\n\t Enter Element to Add : "); scanf("%d", &num); append(&root, root, num); break; case 3: printf("\n"); getch(); exit(0); break; case 4: printf("\n\t Enter element to insert : "); scanf("%d", &num); addatbeg(&root, num); break; } } }
int main() { struct node *p; int f;f=1; p=NULL; append(&p,1); //p is the pointer to the first struct node variable append(&p,2); //every variable has it's own data and the address to he next unnamed dynamically allocated variable of the struct type append(&p,3);append(&p,4); append(&p,6);append(&p,10); addatbeg(&p,1); addafter(&p,8,6); display(p); add(&p,9);add(&p,11); printf(" p->link->link->num= %d ",p->link->link->num); dlt(&p,f); printf("\nAftre deletion of node %d : ",f); display(p); reverse(&p); printf("\nAfter reversal:"); display(p); getch(); return 0; }
void addatpos(struct node **q,int pos) { struct node *temp,*r; int i; if(pos==0) { addatbeg(q); return; } temp=*q; for(i=1; i<pos; i++) { temp=temp->link; if(temp==NULL) { printf("There Are less Than %d Elements In List",pos); return; } } r=getnode(); getdata(r); r->link=temp->link; temp->link=r; }
main() { int choice,data,item; struct node *start=NULL; while(1) { printf("1.Create List\n"); printf("2.Display\n"); printf("3.Add to empty list\n"); printf("4.Add at beginning\n"); printf("5.Add at end\n"); printf("6.Add after\n"); printf("7.Add before\n"); printf("8.Delete\n"); printf("9.Reverse\n"); printf("10.Quit\n"); printf("Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1: start=create_list(start); break; case 2: display(start); break; case 3: printf("Enter the element to be inserted : "); scanf("%d",&data); start=addtoempty(start,data); break; case 4: printf("Enter the element to be inserted : "); scanf("%d",&data); start=addatbeg(start,data); break; case 5: printf("Enter the element to be inserted : "); scanf("%d",&data); start=addatend(start,data); break; case 6: printf("Enter the element to be inserted : "); scanf("%d",&data); printf("Enter the element after which to insert : "); scanf("%d",&item); start=addafter(start,data,item); break; case 7: printf("Enter the element to be inserted : "); scanf("%d",&data); printf("Enter the element before which to insert : "); scanf("%d",&item); start=addbefore(start,data,item); break; case 8: printf("Enter the element to be deleted : "); scanf("%d",&data); start=del(start,data); break; case 9: start=reverse(start); break; case 10: exit(1); default: printf("Wrong choice\n"); }/*End of switch*/ }/*End of while*/ }/*End of main()*/
int main() { int choice,n,m,po,i; start=NULL; while(1) { printf("1.Create List\n"); printf("2.Add at begining\n"); printf("3.Add after\n"); printf("4.Delete\n"); printf("5.Display\n"); printf("6.Count\n"); printf("7.Reverse\n"); printf("8.exit\n"); printf("Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("How many nodes you want : "); scanf("%d",&n); for(i=0;i<n;i++) { printf("Enter the element : "); scanf("%d",&m); create_list(m); } break; case 2: printf("Enter the element : "); scanf("%d",&m); addatbeg(m); break; case 3: printf("Enter the element : "); scanf("%d",&m); printf("Enter the position after which this element is inserted : "); scanf("%d",&po); addafter(m,po); break; case 4: printf("Enter the element for deletion : "); scanf("%d",&m); del(m); break; case 5: display(); break; case 6: count(); break; case 7: rev(); break; case 8: //exit(); default: printf("Wrong choice\n"); }/*End of switch*/ }/*End of while*/ getch(); return 0; }/*End of main()*/