65 lines
1.2 KiB
C++
Executable File
65 lines
1.2 KiB
C++
Executable File
#include "listE.h"
|
|
#include "setE.h"
|
|
#include <iostream>
|
|
using std::cout;
|
|
using std::endl;
|
|
|
|
template <class E> void output(List<E>& list) {
|
|
for (int i = 0; i < list.length(); i++) {
|
|
cout << list[i] << ' ';
|
|
}
|
|
if (list.length() == 0) {
|
|
cout << "(Empty)";
|
|
}
|
|
cout << endl;
|
|
}
|
|
|
|
int main() {
|
|
int nums[5] = {1, 4, 6, 8, 3};
|
|
List<int> aList;
|
|
List<int> bList(nums, 5);
|
|
output(bList);
|
|
try {
|
|
aList.remove(0);
|
|
}
|
|
catch(ValueError) {
|
|
std::cerr << "There is an ValueError" << std::endl;
|
|
}
|
|
aList.append(3);
|
|
aList.append(8);
|
|
aList.append(9);
|
|
aList.append(12);
|
|
aList.insert(1, 20);
|
|
output(aList);
|
|
|
|
cout << aList.pop() << endl;
|
|
output(aList);
|
|
|
|
aList.pop(2);
|
|
output(aList);
|
|
|
|
cout << aList.contains(3) << ' ' << aList.contains(15) << endl;
|
|
|
|
try {
|
|
aList.index(15);
|
|
}
|
|
catch(ValueError) {
|
|
std::cerr << "There's no 15 in this list." << std::endl;
|
|
}
|
|
|
|
aList.clear();
|
|
output(aList);
|
|
|
|
cout << "\n----------\n" << endl;
|
|
|
|
Set<int> aSet;
|
|
aSet.show();
|
|
|
|
aSet.add(2);
|
|
aSet.add(3);
|
|
aSet.show();
|
|
|
|
aSet.remove(2);
|
|
aSet.show();
|
|
return 0;
|
|
} |