-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmain.cpp
110 lines (84 loc) · 2.77 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//*****************************************************************************************************
//
// This program demonstrates the use of the AList class by instantiating an array-based list of
// short integers and performing its methods.
//
// Other files required:
// 1. aList.h - header file for the AList class
//
//*****************************************************************************************************
#include "aList.h"
#include <iostream>
using namespace std;
//*****************************************************************************************************
void displayAList(bool success, AList<short> &shortList);
void checkState(AList<short> &shortList);
//*****************************************************************************************************
int main() {
AList<short> shortList(3);
short num;
int i = 0;
bool success;
checkState(shortList);
num = 10;
success = shortList.insertFront(num);
if (success)
cout << "insert front: " << num << endl;
displayAList(success, shortList);
num = 20;
success = shortList.insertAtIndex(num, i);
if (success)
cout << "insert index " << i << ": " << num << endl;
displayAList(success, shortList);
num = 30;
success = shortList.insertBack(num);
if (success)
cout << "insert back: " << num << endl;
displayAList(success, shortList);
return 0;
}
//*****************************************************************************************************
void displayAList(bool success, AList<short> &shortList) {
short min;
int cap,
numVal;
if (success) {
shortList.display();
shortList.getSmallest(min);
cap = shortList.getCapacity();
numVal = shortList.getNumValues();
if (numVal > 0)
cout << "capacity: " << cap
<< "\tnumVal: " << numVal
<< "\tsmallest: " << min << endl;
else
cout << "capacity: " << cap
<< "\tnumValues: " << numVal << endl;
cout << endl;
}
checkState(shortList);
}
//*****************************************************************************************************
void checkState(AList<short> &shortList) {
if (shortList.isFull())
cerr << "list is full\n\n";
else if (shortList.isEmpty())
cerr << "list is empty\n\n";
}
//*****************************************************************************************************
/*
list is empty
insert front: 10
[0] 10
capacity: 3 numVal: 1 smallest: 10
insert index 0: 20
[0] 20
[1] 10
capacity: 3 numVal: 2 smallest: 10
insert back: 30
[0] 20
[1] 10
[2] 30
capacity: 3 numVal: 3 smallest: 10
list is full
*/