Assignment 4
Assignment 4
#pragma once
#include <iostream>
#include <cassert>
class listType
public:
void sort();
//Function to sort the list.
//Postcondition: The list elements are in ascending order.
//specified by position.
private:
int maxSize; //variable to store the maximum size
//of the list
int length; //variable to store the number of elements in
// the list
elemType* list; //pointer to the array that holds the
//list elements
};
template <class elemType>
bool listType<elemType>::isEmpty()const
{
return (length == 0);
}
return maxSize;
maxSize = listSize;
length = 0;
int min;
elemType temp;
}
template<class elemType>
void listType<elemType>::print() const
{
int i;
}//end print
}
-----------------------------------------------------------------------------------
------------------------------------------------------------
#include <iostream>
#include "listType.h"
int main()
{
listType<int>intList(100);
int index;
int number;
cout << "-----------------------------------------------" << endl;
cout << "Enter 5 integers: " << endl;
for (index = 0; index < 5; index++)
{
cin >> number;
intList.insertAt(number, index);
}
cout << endl;
cout << "-----------------------------------------------" << endl;
cout << "intList: ";
intList.print();
cout << "-----------------------------------------------" << endl;
//Sort intList
intList.sort();
cout << " After sorting, intList: ";
intList.print();
cout << "-----------------------------------------------" << endl;
int intListSize;
cout << "Enter the size of the integer " << "list: ";
cin >> intListSize;
cout << endl;
listType<int> intList2(intListSize);
cout << "Enter " << intListSize << " integers: " << endl;
for (index = 0; index < intListSize; index++)
{
cin >> number;
intList2.insertAt(number, index);
}
cout << endl;
cout << "intList2: ";
intList2.print();
cout << "Length of intList2: " << intList2.getLength() << endl;
cout << "Maximum size of intList2: " << intList2.getMaxSize() << endl;
cout << "-----------------------------------------------" << endl;
//Sort intList2
intList2.sort();
cout << "After sorting, intList2: ";
intList2.print();
cout << "-----------------------------------------------" << endl;
intList2.search();
cout << endl;
cout << "-----------------------------------------------" << endl;
intList2.remove();
cout << endl;
cout << "-----------------------------------------------" << endl;
system("pause");
return 0;
}