Question: C language Using the following code: #include #include typedef struct node_def node; struct node_def { int val; node *next; }; node *makeNode(int val); node *insertFront(node
C language
Using the following code:
#include#include typedef struct node_def node; struct node_def { int val; node *next; }; node *makeNode(int val); node *insertFront(node *head, node *new); node *deleteNode(node *head, int val); node *modifyNode(node *head, int old, int new); int inList(node *head, int val); int length(node *head); void lookForDupes(node *head); void printList(node *head); int main() { return 0; } node *makeNode(int val) { node *tmp = malloc(sizeof(node)); tmp->val = val; tmp->next = NULL; return tmp; } node *insertFront(node *head, node *new) { if (head == NULL) head = new; else { new->next = head; head = new; } return head; } node *deleteNode(node *L, int val) { } node *modifyNode(node *L, int old, int new) { } int inList(node *L, int val) { //returns 1 if found, 0 if not found } int length(node *L) { } void lookForDupes(node *L) { } void printList(node *head) { node *tmp = head; int i = 0; for (i = 1; tmp != NULL; ++i) { printf("%4d ", tmp->val); if (i % 10 == 0) printf(" "); tmp = tmp->next; } if ((i-1) % 10) printf(" "); return; }
For this assignment you will perform several tasks
1. Ask the user to enter in the number of nodes for the linked list
2. Generate a list with the # of nodes specified by the user
Each node will contain a random number with the range 0-9999
3. Print out the generated list (10 per line)
------------------------------------------------------------------------------
4. Ask the user to enter in a number
- Search the list and see if the number is in the list
5. If the number is in the list, change that node's value to a value
specified by the user
- print the list to verify that the specified node was changed
6. Search the list again for a value, if found, delete that node
- print the list to verify that the node was deleted
EXTRA CREDIT:
7. Search the list and find out if there are any duplicate values in
the list and print them out
Required Functions:
(Functions that have a P are functions you are allowed to print in)
makeNode() - create a node for your list, should return a node *
insertFront() - add the new node to the front of the list
P printList() - print out our linked list
P deleteNode() - given a value, search the list and remove the node with
that value
modifyNode() - given a new and old value, search the list for the old
value and change it to the new one
inList() - given a value, searches the list for that value
EXTRA CREDIT:
P lookForDupes() - search the linked list looking for any duplicate
values in the list
Example:
----------------------------------------------------------------------
$ ./a.out
How many nodes? 20
8430 2799 4782 9705 7778 7618 473 878 8270 7042
4739 8414 188 1474 7954 7162 9796 3059 5374 212
Enter a number to search for: 2799
Found in list
Change to what value? 1
8430 1 4782 9705 7778 7618 473 878 8270 7042
4739 8414 188 1474 7954 7162 9796 3059 5374 212
Enter a number to remove: 1
1 was deleted from the list
8430 4782 9705 7778 7618 473 878 8270 7042 4739
8414 188 1474 7954 7162 9796 3059 5374 212
No Dupes Found :(
$ ./a.out
How many nodes? 15
9564 6561 7377 2904 4080 255 5940 4604 6782 4102
29 1955 5023 5536 8641
Enter a number to search for: 9564
Found in list
Change to what value? 1111
1111 6561 7377 2904 4080 255 5940 4604 6782 4102
29 1955 5023 5536 8641
Enter a number to remove: 0
No node to delete
1111 6561 7377 2904 4080 255 5940 4604 6782 4102
29 1955 5023 5536 8641
No Dupes Found :(
$ ./a.out
How many nodes? 10
8163 285 4482 4425 5799 6812 7003 5507 1190 6958
Enter a number to search for: 0
Not in list
Enter a number to remove: 8163
8163 was deleted from the list
285 4482 4425 5799 6812 7003 5507 1190 6958
No Dupes Found :(
$ ./a.out
How many nodes? 5
8667 5337 2002 2216 4007
Enter a number to search for: 4007
Found in list
Change to what value? 8667
8667 5337 2002 2216 8667
Enter a number to remove: 2002
2002 was deleted from the list
8667 5337 2216 8667
Dupe found: 8667
Dupe found: 8667
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
