Starting from:
$30

$24

Lab 7 (30 Points) Solved

Objectives:

    • Learn how to create and use a linked list ADT

Description:

1.    Node * createLinkedList(int numOfNodes)

        o Create a linked list using createNode(key) where 1 ≤ key ≤ 10, using rand().

        o Insert the newly created Node at the head of the linked list.

        o Return: the head of the linked list.

    2. Node * createNode(int num)

        o This function will create a Node struct using malloc() and initialize the Node key with num variable and


Node next with NULL.







typedef


{

o  Return: the newly created Node.

struct nodeL

3.
Node * findNode(int searchKey, Node * head)

int key;

o  Input: an integer search key, and first node of the linked list.







* next;

o  Search the Node that contains the searchKey.

struct nodeL


o  Return: Node pointer to the first found key node or NULL if not found.
} Node;
4.
void displayList(Node *head)












        o Input: first node of the linked list.

        o Display the keys in the linked list.

    5. void freeList(Node *head)

        o Input: first node of the linked list.

        o Free all the Nodes in the linked list.

    6. Main function

        o Create a linked list with 15 Nodes using createLinkedList().

        o Display your linked list with the displayList().

        o Print out the result as shown in the Example below and use what return back from findNode().

        o Free up the linked list using freeList().

Every user-defined function must have a comment describing:

    • What function does;

    • What parameter values are;

    • What value it returns.

Example from the terminal window:


$ ./a.out

My linked list’s keys: 2 3 4 5 10 7 8 9 4 3 1 2 3 4 6

Enter an integer key between 1 to 10: 4

The key 4 is found, and the next node of the key 4 Node is located at 0x7ffeefbff4d8.

$ ./a.out

My linked list’s keys: 2 3 4 5 6 7 8 9 3 9 4 5 6 7 2

Enter an integer key between 1 to 10: 10

The key 10 is not found!

1
Section A

Grading Criteria:


Main program:
4 points

createLinkedList function:
10 points

createNode function:
4 points

findNode function:
4 points

displayList function:
4 points

freeList function:
4 points

Note:

    • If your code does not compile with –Wall and –Werror, you will receive a zero for this assignment.

    • You need to finish at least three peer reviews within three days of this lab. Otherwise, you will get a 20% penalty.

    • You will lose points if you don’t have enough comments.




























More products