100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

Linked Lists Class File

Rating
-
Sold
-
Pages
3
Uploaded on
06-11-2025
Written in
2025/2026

The provided code defines a simple linked list program in C++ with functionalities to insert, delete, and display items either from left to right or right to left. **Key functions:** 1. **`insertItem(LinkedLists *& head)`**: This function adds a new item to the linked list. It prompts the user for an ID and name, creates a new node, and updates the pointers accordingly. 2. **`deleteItem(LinkedLists *& head)`**: This function deletes a node from the linked list based on user-input ID. It handles various cases, including empty lists and deleting from the head or end. 3. **`displayOptions()`**: This function presents the user with options for displaying the list and returns the chosen option. 4. **`displayLtoR(LinkedLists *& head)`**: Displays the list from the head to the end, printing IDs and names of each node. 5. **`displayRtoL(LinkedLists *& head)`**: Displays the list from the end to the head, navigating back through the linked list. **Main Execution:** In the `main()` function, five items are inserted into the list, one item is deleted, and the user is prompted to choose how to display the list. The corresponding display function is called based on the user's input. Overall, the program allows for basic manipulation and viewing of a doubly linked list.

Show more Read less








Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
November 6, 2025
Number of pages
3
Written in
2025/2026
Type
Other
Person
Unknown

Content preview

#include "LinkedLists.h"

void insertItem(LinkedLists *& head);
void deleteItem(LinkedLists *& head);
char displayOptions();
void displayLtoR(LinkedLists *& head);
void displayRtoL(LinkedLists *& head);

int main()
{
LinkedLists * head = NULL;
char answer;

// insert 5 items into the list
for (int i = 0; i < 5; i++)
{
insertItem(head);
}
// delete an item from the list
deleteItem(head);

answer = displayOptions();

if (toupper(answer) == 'A')
// display from left to right
displayLtoR(head);
else
// display from right to left
displayRtoL(head);

return 0;
}

void insertItem(LinkedLists *& head)
{
LinkedLists * temp = new LinkedLists;

cout << "ID: ";
cin >> temp->ID;
cout << "NAME: ";
cin >> temp->name;

temp->next = head;
temp->back = NULL;

if (head != NULL)
head->back = temp;

head = temp;
}

void deleteItem(LinkedLists *& head)
{
LinkedLists * lead;
LinkedLists * follow;
int IDnum;

lead = follow = head;
$15.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
tinahuynh

Get to know the seller

Seller avatar
tinahuynh California State University, Long Beach
View profile
Follow You need to be logged in order to follow users or courses
Sold
New on Stuvia
Member since
1 month
Number of followers
0
Documents
68
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions