Lab 6 Solution

$29.99 $18.99

Goals Build single linked lists using pointers Learn how to manipulate linked lists In this lab, you will create simple single linked structures consisting of Node objects. Each node will have a pointer to the next node. You will use a head pointer to keep track of the first node in the linked list, and…

You’ll get a: . zip file solution

 

 
Categorys:
Tags:

Description

Rate this product

Goals

  • Build single linked lists using pointers

  • Learn how to manipulate linked lists

In this lab, you will create simple single linked structures consisting of Node objects. Each node will have a pointer to the next node. You will use a head pointer to keep track of the first node in the linked list, and a tail pointer to keep track of the last node in the linked list. Set both head and tail to NULL when the list is empty.

All of the code manipulating the linked list should be in the main function. For this lab, you will not implement the linked list operations using functions/methods. The idea is to focus on the low-level manipulation of the links that connect the nodes in the list.

  1. Create the linked list: store integer values entered by the user in the linked list. Each node in the list should store one value. Use a menu to get user input values. After the user has entered the sequence of values, the program should print the values in order. Think about how to traverse the list in order to print the values. Meanwhile, you need to set the head and tail pointers to point to the first and last node in the list.

  1. Get the head or tail node value: print the values of head or tail node in screen. If the list is empty, print a note as “List is empty!!”

  1. Delete the head or tail value: ask the user whether to delete the node in the head or tail of the list. When user chooses one, delete that node by manipulate pointers and print the new head/tail node value. If the list is already empty, print a note like “Deleting failed, list is empty!! Remember to free the memory after deleting.

Finally, give users options to exit the program or do it again.

Example running:

Welcome to my linked list!

Enter a number: 100

Do you want another num(y or n): y

Enter a number: 30

Do you want another num(y or n): y

Enter a number: 50

Do you want another num(y or n): y

Enter a number: 10

Do you want another num(y or n): n

Your linked list is: 100 30 50 10

Do you want to do get head or tail node value (h or t): t

Tail node is: 10

Do you want to delete head or tail node (h or t): h

The new head node is 30!

Do you want to do this again (y or n)? n

Extra Credit: 20%

Make a better menu so that user can add new nodes to the list on the tail side, delete from head or tail, traverse print the list, get the head/tail node value in any sequence.

Grading

  • Programming style: 10%

  • Create the linked list by user input and set the head and tail pointers: 40%

  • Correctly traverse and print the list in order: 20%

  • Print the head or tail node: 10%

  • Delete the head or tail node and print the new head/tail: 20%