• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 1 fuera de 3 páginas
Otro

Linked Lists Class File

Document preview thumbnail
Vista previa 1 fuera de 3 páginas

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.

Vista previa del contenido

#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;

Información del documento

Subido en
6 de noviembre de 2025
Número de páginas
3
Escrito en
2025/2026
Tipo
Otro
Personaje
Desconocido
$15.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
68
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes