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

Sorted and Unsorted List CPP File

Rating
-
Sold
-
Pages
3
Uploaded on
06-11-2025
Written in
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.

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 "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
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