-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW3_TreeSortMain.cpp
68 lines (52 loc) · 1.11 KB
/
HW3_TreeSortMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//BRIAN DUENAS
//5-30-17
// to be used for HW3
// CSE 330, Spring 2017, Kerstin Voigt, May 2017
#include <iostream>
#include <stdlib.h>
#include <vector>
#include "HW3Set.h"
using namespace std;
template <class T>
void tree_sort(vector<T>&);
int main()
{
vector<int> myvec;
int k, next;
cout << "How many items? ";
cin >> k;
cout << endl;
for (int i = 1; i <= k; i++)
{
cout << "Number: ";
cin >> next;
//cout << endl;
myvec.push_back(next);
}
cout << endl;
cout << "Items in vector: " << endl;
for (int i = 0; i < myvec.size(); i++)
cout << myvec[i] << " ";
cout << endl << endl;
tree_sort(myvec);
cout << "Items in sorted vector: " << endl;
for (int i = 0; i < myvec.size(); i++)
cout << myvec[i] << " ";
cout << endl << endl;
system("Pause");
}
template <class T>
void tree_sort(vector<T>& vec)
{
Set<T> aset;
// complete in HW3
for (int i=0; i < vec.size(); i++)
aset.insert(vec[i]);
typename Set<T>::iterator itr;
int i=0;
for (itr = aset.begin(); itr != aset.end(); itr++){
vec[i] = *itr;
i++;
}
return;
}