Advertisement
ahamed210

Linked_list

Oct 5th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "prepend.h" //here have to add this header file first because here is the basic user defiend variable declared
  4. #include "print_linked_list.h"
  5. #include "append.h"
  6. #include "insert.h"
  7. #include "remove_node.h"
  8. #include "search.h"
  9.  
  10. int main()
  11. {
  12.     Node *head=NULL, *temp;
  13.     int choise;
  14.     while(choise)
  15.     {
  16.     Node *new_node = (Node *)malloc(sizeof(Node));
  17.     printf("Enter Node item : ");
  18.     scanf("%d", &new_node->data);
  19.     new_node->next = NULL;
  20.  
  21.     if(head == NULL){
  22.         head = temp = new_node;
  23.     }
  24.     else{
  25.         temp->next = new_node;
  26.         temp = new_node;
  27.     }
  28.     printf("enter choise 1 or 0 : ");
  29.     scanf("%d", &choise);
  30.     }
  31.     //insert in any position
  32.     add_node(head);
  33.  
  34.     //adding node at the begaining
  35.     head = prepend(head);
  36.     append(head);
  37.     head = prepend(head);
  38.  
  39.     //append
  40.     append(head);
  41.     append(head);
  42.     head = prepend(head);
  43.     append(head);
  44.  
  45.     //insert in any position
  46.     add_node(head);
  47.  
  48.  
  49.     //printing the linked list
  50.     print_linked_list(head);
  51.  
  52.     //delete node
  53.     int item;
  54.     printf("\n\nEnter the number you want to delete from linked list : ");
  55.     scanf("%d", &item);
  56.     head = remove_node(head, item);
  57.  
  58.     print_linked_list(head);
  59.  
  60.     //searching a perticular item in linked list
  61.     int number;
  62.     printf("\n\nEnter the number you are searching in linked list : ");
  63.     scanf("%d", &number);
  64.     Node *searched_node = search(head, number);
  65.     printf("%p\n", searched_node->next);
  66.  
  67.     print_linked_list(head);
  68.     return 0;
  69. }
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement