Advertisement
immuntasir

Linked List 1

Sep 6th, 2015
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct node {
  4. int val;
  5. struct node * next;
  6. } node_t;
  7. void print(node_t * head) {
  8. node_t * current = head;
  9.  
  10. while (current != NULL) {
  11. printf("%d\n", current->val);
  12. current = current->next;
  13. }
  14. }
  15. void menu(node_t *head) {
  16. int n;
  17. printf("What operation do you want to execute?\n");
  18. printf("Press 1 to print all elements.\n");
  19. printf("Press 0 to exit.\n");
  20. scanf("%d", &n);
  21. switch(n) {
  22. case 1:
  23. print(head);
  24. break;
  25. }
  26. if (n!=0) menu(head);
  27. }
  28. int main() {
  29. node_t *head = NULL;
  30. head = malloc(sizeof(node_t));
  31. int num;
  32. printf("Enter the first integer: ");
  33. scanf("%d", &num);
  34. head->val = num; // head er address e jei node ta ache tar val er man rakhlam num
  35. head->next = NULL; // porer address hishebe rakhlam NULL. orthat ekhanei shes
  36.  
  37. menu(head);
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement