Question
( C++ data structure program: I have tried to complete this exercise reading the book multiple times and also watching a video, however, I'm struggling
( C++ data structure program:
I have tried to complete this exercise reading the book multiple times and also watching a video, however, I'm struggling in resolving this program...if someone can explain it to me and show it to me in more details . I'm completely lost..
(please don't just copy the code from other posts and paste it, because I won't be able to understand)
here's is the exercise and what I've got so far:
An Unsorted Type ADT is to be extended by the addition of function SplitLists, which as the following specifications: SplitLists(UnsortedType list, ItemType item, UnsortedType& list1. UnsortedType& list2) Function:Divides
list into two lists according to the key of item. Preconditions:
list has been initialized and is not empty. Post conditions: list1 contains all the items of list whose keys are less than or equal to items key; list2 contains all of the itemsof
list whose keys are greater than items key. a. Implement SplitLists as an array-based member function of the Unsorted List ADT. b. Implement SplitLists as a linked member function of the Unsorted List ADT.
//header name : SplitList.h
class UnsortedType {
public:
UnsortedType();
//int splitLists();
void makeEmpty();
//int itemtype();
//void getList();
bool isFull() const;
//int getLength() const;
void putItem(int item);
void deleteItem(int item);
//void printItem();
void show();
private:
int length;
//int compareItem;
int info[4];
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SplitList.cpp
#include
#include"SplitList.h"
using namespace std;
//constructor gives length a value
UnsortedType::UnsortedType()
{
length = 0;
}
void UnsortedType::putItem(int item)
{
if (isFull()) return;
info[length] = item;
length++;
}
bool UnsortedType::isFull() const {
return (length == 4);
}
void UnsortedType::makeEmpty()
{
length = 0;
}
void UnsortedType::deleteItem(int item)
{
for (int i = 0; i < 4; i++) if
(info[1] == item)
info[i] = info[length - 1];
length--;
}
void UnsortedType::show()
{
for (int i = 0; i < 4; i++)
cout << info[i] << endl;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//main function
#include "SplitList.h"
int main()
{
UnsortedType list;
list.putItem(8);
list.putItem(5);
list.putItem(6);
list.putItem(7);
list.putItem(3);
list.show();
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started