-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (68 loc) · 2.28 KB
/
main.cpp
File metadata and controls
84 lines (68 loc) · 2.28 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//this file was compiled with the following command: g++ p1.cpp p2.cpp p3.cpp p4.cpp main.cpp -std=c++11
#include "p4.h"
#include "p3.h"
#include "p2.h"
#include "p1.h"
#include <vector>
#include <iostream>
#include <cstdlib>
#include <ctime>//for time()
#include <cmath>//for rand
using namespace std;
int main(int argc, char const *argv[]) {
//Problem 1 sample --------------------
cout << endl << "Problem 1 sample --------------------" << endl;
srand(time(NULL));
rand();
vector <int> v;
for(int i = 0; i < 7; i++) {
int temp = rand()%10;
if(rand()%2 == 0) {
temp *= -1;
}
v.push_back(temp);
}
cout << "unsorted array:";
for(auto i: v) {
cout << i << ", ";
}
cout << endl;
quicksort(v); //call to quicksort from p1.h
cout << "sorted array: ";
for(auto i: v) {
cout << i << ", ";
}
cout << endl;
//Problem 2 sample --------------------
cout << endl << "Problem 2 sample --------------------" << endl;
cout << "Testing atoi()" << endl;
cout << atoi(string("700a")) << endl; //call to atoi from p2.h
cout << atoi(string("70-09")) << endl; //call to atoi from p2.h
cout << atoi(string("700")) << endl; //call to atoi from p2.h
cout << endl << "Testing itoa()" << endl;
char str[30];
cout << itoa(-2147483647, str, 10) << endl; //call to itoa from p2.h
cout << itoa(-234, str, 10) << endl; //call to itoa from p2.h
cout << itoa(270, str, 16) << endl; //call to itoa from p2.h
cout << itoa(1750, str, 16) << endl; //call to itoa from p2.h
//Problem 3 sample --------------------
cout << endl << "Problem 3 sample --------------------" << endl;
vector<int> houses;
vector<int> a = {1, 2, 3, 1};
for(int i: a) {
cout << i << " ";
}
cout << endl;
cout << rob_max_value(a) << endl; //call to rob_max_value from p3.h
//Problem 4 sample --------------------
cout << endl << "Problem 4 sample --------------------" << endl;
Node* head = new Node(1);
head->addNode(2);
head->addNode(3);
head->addNode(4);
head->addNode(5);
head->printList();
deleteNthToLastNode(head, 2); //call to deleteNthToLastNode from p4.h
head->printList();
return 0;
}