Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int value;
- struct node *next;
- }*t1,*t2,*t3;
- struct node* head = NULL; //(struct node *)malloc(sizeof(struct node));
- //End of structure
- void ins()
- {
- int data;
- printf("\nEnter Data:");
- scanf("%d",&data);
- t1 = (struct node*)malloc(sizeof(struct node));
- if(head == NULL)
- {
- t1->value = data;
- t1->next = NULL;
- head = t1;
- }// end of if
- else
- {
- t1->value = data;
- t1->next = head;
- head = t1;
- }// end of if
- }// Insert
- void dels(int pos)
- {
- t2 = head;
- if(head == NULL){
- printf("list empty");
- }//end of if
- else{
- while(t2->next->value != pos)
- {
- t2 = t2->next;
- }
- t3 = t2->next;
- t2->next = t3->next;
- free(t3);
- }// end of else
- }//end of dels
- void disp()
- {
- struct node *t4 = head;
- if(head == NULL){
- printf("\n Empty");
- }
- else
- {
- while(t4->next != NULL)
- {
- printf(" %d ",t4->value);
- t4 = t4->next;
- }
- }
- }
- int main()
- {
- int ch;
- int val;
- char x = 'y';
- while(x != 'n')
- {
- printf("ch: ");
- scanf("%d",&ch);
- if(ch == 1)
- {
- ins();
- }
- if(ch == 2)
- {
- printf("Val: ");
- scanf("%d",&val);
- dels(val);
- }
- if(ch == 3){
- disp();
- }
- printf(" y/n: ");
- scanf("%c",&x);
- }//end of while
- return 0;
- }// eom
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement