Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- typedef struct node_def node;
- struct node_def
- {
- int val;
- node *next;
- };
- node *makeNode(int val);
- node *insertFront(node *head, node *new);
- void printList(node *head);
- node *deleteNode(node *head, int val);
- node *modifyNode(node *head, int old, int new);
- int inList(node *head, int val);
- void lookForDupes(node *L);
- // int length(node *L);
- node *head = NULL;
- int main()
- {
- node *tmp = NULL;
- srand(time(NULL));
- int num = rand()%10000;
- int val;
- printf("How many nodes? ");
- scanf("%d", &val);
- for (int i=1; i<val; ++i) {
- num = rand()%10000;
- makeNode(num);
- }
- printList(head);
- return 0;
- }
- /**
- * create a node for your list
- * return a pointer to that node (node *)
- */
- node *makeNode(int val)
- {
- node *new = malloc(sizeof(node));
- printf("\n %d\n", val);
- new->val = val;
- new->next = head;
- insertFront(head, new);
- return(new);
- }
- /**
- * add a node to the front of the list
- * return new front of list
- */
- node *insertFront(node *head, node *new)
- {
- head = new;
- new = NULL;
- }
- /**
- * P: print out the linked list (10 per line)
- */
- void printList(node *head)
- {
- while (head != NULL) {
- printf("hello");
- printf("linked list = %d ", head->val);
- head = head->next;
- }
- }
- /**
- * P: given a value, search the list and remove the node with that value
- */
- node *deleteNode(node *head, int val)
- {
- }
- /**
- * given a new and old value, search the list for the old value and change it to the new one
- */
- node *modifyNode(node *head, int old, int new)
- {
- }
- /**
- * given a value, searches the list for that value
- * return true or false (or an integer 0 or 1 that you can use as true or false)
- */
- int inList(node *head, int val)
- {
- }
- /**
- * P: search the linked list looking for any duplicate values in the list
- */
- void lookForDupes(node *L)
- {
- }
- /**
- * --Optional--
- * returns the number of nodes in a given list
- */
- // int length(node *L)
- // {
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement