Lab 7 Solution

$30.00 $24.00

Objectives: Learn how to create and use a linked list ADT Description: 1. Node * createLinkedList(int numOfNodes) Create a linked list using createNode(key) where 1 ≤ key ≤ 10, using rand(). Insert the newly created Node at the head of the linked list. Return: the head of the linked list. Node * createNode(int num) This…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:
Tags:

Description

5/5 – (2 votes)

Objectives:

  • Learn how to create and use a linked list ADT

Description:

1. Node * createLinkedList(int numOfNodes)

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

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

    1. Return: the head of the linked list.

  1. Node * createNode(int num)

    1. 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)

    1. Input: first node of the linked list.

    1. Display the keys in the linked list.

  1. void freeList(Node *head)

    1. Input: first node of the linked list.

    1. Free all the Nodes in the linked list.

  1. Main function

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

    1. Display your linked list with the displayList().

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

    1. 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.

2

Lab 7 Solution
$30.00 $24.00