Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2. #include < stdlib.h>
  3. typedef int list_item;
  4. typedef struct list {
  5. int data;
  6. struct list* next;
  7. }list;
  8.  
  9. struct list* head = NULL, * pos;
  10.  
  11. int isEmpty(list* head) {
  12. return (head == NULL) ? 1 : 0;
  13. }
  14.  
  15. struct list* addNode(int num)
  16. {
  17. struct list *node = (list*)malloc(sizeof(list));
  18. node-> data = num;
  19. node->next = NULL;
  20. if (isEmpty(head))
  21. {
  22. head = node;
  23. head->next = NULL;
  24. pos = head;
  25. }
  26. else {
  27. pos->next = node;
  28. pos = pos->next;
  29. pos->next = head;
  30. }
  31. }
  32. void display()
  33. {
  34. struct list* current;
  35. if (isEmpty(head))
  36. {
  37. printf("List is empty");
  38. }
  39. else {
  40. current = head;
  41. do {
  42. printf("%d", current->data);
  43. current = current->next;
  44. } while (current != head);
  45. printf("\n");
  46. }
  47. }
  48. struct list* bigger(list* head)
  49. {
  50. int max = head->data;
  51. int beforeMax = head->data;
  52. while (head != NULL)
  53. {
  54. if (head->data > max)
  55. {
  56. max = head->data;
  57. }
  58.  
  59.  
  60. else if (head->data < max && head->data > beforeMax)
  61. {
  62. beforeMax = head->data;
  63. }
  64.  
  65. head = head->next;
  66.  
  67. }
  68. return beforeMax;
  69. }
  70.  
  71.  
  72. void main()
  73. {
  74. list* node = head;
  75. int num, len, i;
  76. do {
  77. printf("\nHow many numbers you want in the list ? ");
  78. scanf_s("%d", &len);
  79. if (len <= 0)printf("List must have more numbers than 0");
  80. } while (len <= 0);
  81. printf("\nPlease enter %d numbers", len);
  82. for (i = 0; i < len; i++)
  83. {
  84. scanf_s("%d", &num);
  85. addNode(num);
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement