100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4.2 TrustPilot
logo-home
Otro

Sorted and Unsorted List CPP File

Puntuación
-
Vendido
-
Páginas
3
Subido en
06-11-2025
Escrito en
2025/2026

The code defines two classes, `UnsortedList` and `SortedList`, to manage collections of integers. ### UnsortedList - **Constructor/Destructor**: Initializes the list with a length of 0. - **insertItem(int id)**: Inserts an integer at the end of the list and increments the length. - **deleteItem(int id)**: Searches for an item; if found, it replaces it with the last element and decrements the length. If not found, it outputs a message. - **isFull() / isEmpty()**: Checks if the list is full or empty based on its length. - **displayList()**: Displays all items in the list or indicates if the list is empty. ### SortedList - **Constructor/Destructor**: Initializes the list with a length of 0. - **insertItem(int item)**: Uses binary search to find the correct insert position, shifts elements, and adds the item to maintain order. - **binarySearch(int item)**: Implements a binary search algorithm to locate the position for inserting an item. - **deleteItem(int item)**: Uses linear search to find and remove an item, shifting remaining elements and updating the length. - **linearSearch(int item)**: Searches for an item and returns its location. - **isFull() / isEmpty()**: Checks if the list is full or empty. - **displayList()**: Outputs each number in the list. Both classes manage integers and offer basic functionalities such as insertion, deletion, and display of the list, accommodating both unsorted and sorted data structures.

Mostrar más Leer menos
Institución
Grado








Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Institución
Grado

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

Temas

Vista previa del contenido

#include "UnsortedSorted.h"

UnsortedList::UnsortedList()
{
length = 0;
}
UnsortedList::~UnsortedList() {}

void UnsortedList::insertItem(int id)
{
idNumbers[length] = id;
length++;
}

void UnsortedList::deleteItem(int id)
{
int location = 0;

while (id != idNumbers[location] && location < length)
location++;

// if (location < length)
// {
// idNumbers[location] = idNumbers[length - 1];
// length--;
// }
if (idNumbers[length] == id) // both work
{
idNumbers[location] = idNumbers[length-1];
length--;
}
if (location == length)
{
cout << "The item is not in the list." << endl;
}
}

bool UnsortedList::isFull() const
{
return (length == SIZE);
}
bool UnsortedList::isEmpty() const
{
return (length == 0);
}
void UnsortedList::displayList() const
{
int location = 0;

while (location < length)
{
cout << idNumbers[location] << endl;
location++;
}
if (location > length)
{
cout << "The list is empty." << endl;
}
}
$15.49
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
tinahuynh

Conoce al vendedor

Seller avatar
tinahuynh California State University, Long Beach
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
Nuevo en Stuvia
Miembro desde
1 mes
Número de seguidores
0
Documentos
68
Última venta
-

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Recientemente visto por ti

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