-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
70 lines (50 loc) · 2.53 KB
/
main.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
69
70
#include "linkedqueue.hpp"
#include "contact.hpp"
int main()
{
//LinkedQueue of integers using pointers
std::cout << "Instantiating integers LinkedQueue\n";
LinkedQueue<int>* integerQueue = new LinkedQueue<int>(-1);
std::cout << "Push numbers from 1 to 5..\n";
for (int x = 1; x < 6; x++)
integerQueue->push(x);
std::cout << "Make a new LinkedQueue using the copy constructor to display later on..\n\n";
LinkedQueue<int>* copyIntegerQueue = new LinkedQueue<int>(*integerQueue);
std::cout << "Print the queue..\n";
std::cout << *integerQueue << "\n";
std::cout << "Size: " << integerQueue->size() << "\n\n";
std::cout << "Element at the front: " << integerQueue->top() << "\n\n";
std::cout << "Pop the 3 elements at the top of the queue..\n";
for (int x = 0; x < 3; x++)
std::cout << integerQueue->pop() << " was poped\n";
std::cout << "\nNow the new front of the queue: " << integerQueue->top() << "\n\n";
std::cout << "Print the queue again..\n";
std::cout << *integerQueue << std::endl;
std::cout << "The deep copied LinkedQueue using the copy constructor remained unmodified:" << std::endl;
std::cout << *copyIntegerQueue << std::endl;
std::cout << "Using the copy assignment operator the changes can be seen:" << std::endl;
*copyIntegerQueue = *integerQueue;
std::cout << *copyIntegerQueue << "\n";
//LinkedQueue of Contact objects using pointers
std::cout << "Instantiating contacts LinkedQueue" << std::endl;
LinkedQueue<Contact>* contactQueue = new LinkedQueue<Contact>(Contact("none","none","none","none",-1));
std::cout << "Push 3 contacts to contactQueue\n\n";
contactQueue->push(Contact("1", "Charles", "Disick", "4530 New Grove Avenue", 34));
contactQueue->push(Contact("2", "Kylie", "Michaels", "2310 Buena Vista Apartments", 26));
contactQueue->push(Contact("3", "Jackson", "Smith", "1265 New Dawn Apartments", 45));
std::cout << "Print the queue..\n";
std::cout << *contactQueue;
std::cout << "Size: " << contactQueue->size() << "\n\n";
std::cout << "Element at the top..\n" << contactQueue->top();
std::cout << "\nPop the 3 elements at the top of the queue..";
for (int x = 0; x < 3; x++)
std::cout << "\npoping..\n" << contactQueue->pop();
if (contactQueue->empty())
std::cout << "\ncontactQueue is now empty\n";
//deleting
std::cout << "Freeing memory..\n";
delete integerQueue;
delete copyIntegerQueue;
delete contactQueue;
return 0;
}