Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct x
- {
- int a;
- struct x *ptr;
- }x;
- x *a,*head=NULL,*temp,*temp1;
- void print()
- {
- temp=head;
- while(temp!=NULL)
- {
- printf("%d ",temp->a);
- temp=temp->ptr;
- }
- printf("\n");
- }
- void search()
- {
- printf("Input Value U Want To Search ");
- int b=0,c=0,d;
- scanf("%d",&d);
- printf("\n");
- temp=head;
- while(temp!=NULL)
- {
- c++;
- if(temp->a==d)
- {
- b=1;
- break;
- }
- temp=temp->ptr;
- }
- if(b=0)
- {
- printf("Not Found\n");
- }
- else
- {
- printf("%d Found At Index %d\n",temp->a,c);
- }
- }
- void topinsert()
- {
- printf("Top Insert\n");
- temp=head;
- a=(x*)malloc(sizeof(x));
- scanf("%d",&a->a);
- a->ptr=temp;
- head=a;
- }
- void insert()
- {
- printf("Insert Anywhere\n");
- printf("Position & Value\n");
- int n,b,c;
- a=(x*)malloc(sizeof(x));
- scanf("%d %d",&n,&a->a);
- a->ptr=NULL;
- temp=head;
- if(n==1)
- {
- a->ptr=temp;
- head=a;
- }
- else
- {
- for(b=1;b<n-1;b++)
- {
- temp=temp->ptr;
- }
- a->ptr=temp->ptr;
- temp->ptr=a;
- }
- }
- void deletehead()
- {
- printf("Head Deleted\n");
- temp=head;
- head=head->ptr;
- free(temp);
- }
- void deletee()
- {
- printf("Input Position U Want To Delete ");
- int b,d;
- scanf("%d",&d);
- printf("\n");
- temp=head;
- if(d==1)
- {
- head=head->ptr;
- free(temp);
- }
- else
- {
- for(b=1;b<d;b++)
- {
- temp1=temp;
- temp=temp->ptr;
- }
- temp1->ptr=temp->ptr;
- free(temp);
- }
- }
- void deleteee()
- {
- printf("Input Value U want To Delete ");
- int b,d;
- scanf("%d",&d);
- printf("\n");
- temp=head;
- if(head->a==d)
- {
- head=head->ptr;
- free(temp);
- }
- else
- {
- while(temp->a!=d)
- {
- temp1=temp;
- temp=temp->ptr;
- }
- temp1->ptr=temp->ptr;
- free(temp);
- }
- }
- int main()
- {
- printf("Input The Size Of Array ");
- int n,b,c,d,e=0;
- scanf("%d",&n);
- printf("Input Value\n");
- for(b=0;b<n;b++)
- {
- a=(x*)malloc(sizeof(x));
- scanf("%d",&a->a);
- a->ptr=NULL;
- if(head==NULL)
- {
- head=a;
- }
- else
- {
- temp=head;
- while(temp->ptr!=NULL)
- {
- temp=temp->ptr;
- }
- temp->ptr=a;
- }
- }
- printf("Stored\n");
- print();
- search();
- topinsert();
- print();
- insert();
- print();
- deletehead();
- print();
- deletee();
- print();
- deleteee();
- print();
- printf("\nR Kichu??\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement