• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 3 pages
Other

Linked Lists Class File

Document preview thumbnail
Preview 1 out of 3 pages

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.

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;

Document information

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

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
68
Last sold
-



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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions