#include<stdio.h> typedef struct mynode { int info; struct mynode *Link; }Node; Node *start=NULL,*start2=NULL; //Display Function void display() { Node *tptr=start; printf("\nDATA:\n"); while(tptr) { printf("->%d",tptr->info); tptr=tptr->Link; } } //Split void split() { int pos,step=1; Node *tptr=start,*First=start,*Second=NULL; printf("\nEnter the position from where you want to split:"); scanf("%d",&pos); while(step<pos-1) { tptr=tptr->Link; step++; } Second=tptr->Link; tptr->Link=NULL; Node *ptr1=First,*ptr2=Second; printf("\nList 1:\n"); while(ptr1) { printf("->%d",ptr1->info); ptr1=ptr1->Link; } printf("\nList 2:\n"); while(ptr2) { printf("->%d",ptr2->info); ptr2=ptr2->Link; } } //Insertion void add_node(int value) { Node *newp=NULL,*tptr=NULL; newp=(Node*)malloc(sizeof(Node)); newp->info=value; newp->Link=NULL; if(start==NULL) { start=newp; } else { tptr=start; while(tptr->Link!=NULL) { tptr=tptr->Link; } tptr->Link=newp; } } //Main int main() { int value; char choice; while(1) { printf("Do you want to insert(y/n)?"); scanf("%c",&choice); if(choice == 'y') { printf("\nEnter the info:"); scanf("%d",&value); add_node(value); fflush(stdin); } else { break; } } display(); split(); return 0; }
top of page
Search
Recent Posts
See All#include<stdio.h> #include<stdlib.h> int MAX=0;//Max elements in the queue typedef struct mynode { char info; int pri; struct mynode...
bottom of page
Comments