Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. typedef struct node_def node;
  6. struct node_def
  7. {
  8. int val;
  9. node *next;
  10. };
  11.  
  12. node *makeNode(int val);
  13. node *insertFront(node *head, node *new);
  14. void printList(node *head);
  15. node *deleteNode(node *head, int val);
  16. node *modifyNode(node *head, int old, int new);
  17. int inList(node *head, int val);
  18. void lookForDupes(node *L);
  19. // int length(node *L);
  20.  
  21. node *head = NULL;
  22.  
  23. int main()
  24. {
  25.  
  26. node *tmp = NULL;
  27. srand(time(NULL));
  28. int num = rand()%10000;
  29.  
  30.  
  31.  
  32. int val;
  33. printf("How many nodes? ");
  34. scanf("%d", &val);
  35. for (int i=1; i<val; ++i) {
  36. num = rand()%10000;
  37. makeNode(num);
  38. }
  39. printList(head);
  40. return 0;
  41. }
  42.  
  43. /**
  44. * create a node for your list
  45. * return a pointer to that node (node *)
  46. */
  47. node *makeNode(int val)
  48. {
  49. node *new = malloc(sizeof(node));
  50. printf("\n %d\n", val);
  51. new->val = val;
  52. new->next = head;
  53. insertFront(head, new);
  54. return(new);
  55. }
  56.  
  57. /**
  58. * add a node to the front of the list
  59. * return new front of list
  60. */
  61. node *insertFront(node *head, node *new)
  62. {
  63. head = new;
  64. new = NULL;
  65.  
  66. }
  67.  
  68. /**
  69. * P: print out the linked list (10 per line)
  70. */
  71. void printList(node *head)
  72. {
  73.  
  74. while (head != NULL) {
  75. printf("hello");
  76. printf("linked list = %d ", head->val);
  77. head = head->next;
  78. }
  79. }
  80.  
  81. /**
  82. * P: given a value, search the list and remove the node with that value
  83. */
  84. node *deleteNode(node *head, int val)
  85. {
  86.  
  87. }
  88.  
  89. /**
  90. * given a new and old value, search the list for the old value and change it to the new one
  91. */
  92. node *modifyNode(node *head, int old, int new)
  93. {
  94.  
  95. }
  96.  
  97. /**
  98. * given a value, searches the list for that value
  99. * return true or false (or an integer 0 or 1 that you can use as true or false)
  100. */
  101. int inList(node *head, int val)
  102. {
  103.  
  104. }
  105.  
  106. /**
  107. * P: search the linked list looking for any duplicate values in the list
  108. */
  109. void lookForDupes(node *L)
  110. {
  111.  
  112. }
  113.  
  114. /**
  115. * --Optional--
  116. * returns the number of nodes in a given list
  117. */
  118. // int length(node *L)
  119. // {
  120.  
  121. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement