Question: C++ DATA STRUCTURES I can't complete part B of the project (I just need part b) . I get 6 errors related to the same
C++ DATA STRUCTURES
I can't complete part B of the project (I just need part b). I get 6 errors related to the same line (I would highlight and comment in the line that I get the error).
The error I get are:
(14): error C2143: syntax error: missing ';' before '<' (24): note: see reference to class template instantiation 'UnsortedType
Program instructions:
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: Divideslist 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 items oflist 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 file
#pragma once
#include
template
class UnsortedType {
private:
int length;
vector
public:
UnsortedType(); // constructor
int getLength(); //get length of list
T getListElement(int i);
void putItem(T item);
void show();
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SplitList.cpp
#include
#include "SplitList.h"
using namespace std;
template
UnsortedType
{
length = 0;
}
template
int UnsortedType
{
return this->length;
}
template
T UnsortedType
return list.at(i);
}
template
void UnsortedType
list.push_back(item);
length++;
}
template
void UnsortedType
for (int i = 0; i < length; i++)
cout << "List is: " << list.at(i) << endl;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include
#include "SplitList.h"
using namespace std;
template
void splitLists(UnsortedType
UnsortedType
{
for (int i = 0; i < list.getLength(); i++) {
if (list.getListElement(i) <= item) {
list1.putItem(list.getListElement(i));
}
else
{
list2.putItem(list.getListElement(i));
}
}
}
int main() {
UnsortedType
cout << "orignal item list:" << endl;
list.putItem(8);
list.putItem(6.5);
list.putItem(9.6);
list.putItem(4);
list.putItem(3);
list.putItem(2);
list.putItem(10);
list.show();
UnsortedType
UnsortedType < double > list2;
cout << "Split list in two (list1& list2)" << endl;
cout << "list 1: " << endl;
list1.show();
cout << "list 2:" << endl;
list2.show();
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
