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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include "List.h"
void extra(list&);
/***********************************
* Main
* Test function - DO NOT CHANGE
***********************************/
void main()
{
int age;
list a;
node* p;
string fname, first, last;
fstream infile;
// Get file name
cout << "Enter file name: ";
cin >> fname;
// Open file
infile.open(fname, ios::in);
// Loop through file
while (!infile.eof())
{
infile >> first >> last >> age;
// Process if okay
if (infile.good())
a.insert(first, last, age);
};
// Close
infile.close();
cout << endl << a.length() << " nodes" << endl;
// Find node
cout << endl;
cout << "Enter First and Last name: ";
cin >> first >> last;
cout << endl << "Find: ";
p = a.find(first, last);
if (p != NULL)
{
cout << "Found!" << endl;
p->put(cout);
}
else
cout << "Not found" << endl;
// Remove from list
cout << endl << "Remove: ";
if (a.remove(first, last))
{
cout << "Success!" << endl;
cout << a.length() << " nodes" << endl;
}
else
cout << "Fail" << endl;
// Display forwards
cout << endl;
cout << "Forwards List\n--------------\n";
a.forwards(cout);
cout << endl;
// Display backwards
cout << "Backwards List\n--------------\n";
a.backwards(cout);
cout << endl;
// Extra credit
// extra(a);
}
/***********************************
* Extra Credit
* Test function - DO NOT CHANGE
***********************************/
/*
void extra(list &a)
{ int i,n;
node_ptr map[4];
string first,last;
// Find node
cout << endl;
cout << "Enter First and Last name: ";
cin >> first >> last;
n = a.findall(first,last,map,4);
// Display forwards
cout << endl;
cout << "Find List\n--------------\n";
for(i=0;i<n;i++)
map[i]->put(cout);
}
*/
Expected Output:
Enter file name: People.txt
10 nodes
Enter First and Last name:
Mark Bowman
Find: Found!
Bowman Mark 13
Remove: Success!
9 nodes
Forwards List
|
Bowman David 45
Bowman Frank 37
Bowman John 30
Bowman Mark 42
Bowman Richard 47
Christensen Ann 70
Cox Susan 36
Gueller Kathleen 34
Morales Carlos 68
Backwards List
--------------
Morales Carlos 68
Gueller Kathleen 34
Cox Susan 36
Christensen Ann 70
Bowman Richard 47
Bowman Mark 42
Bowman John 30
Bowman Frank 37
Bowman David 45
Resulting Output:
Enter file name: People.txt
10 nodes
Enter First and Last name: Mark Bowman
Find: Found!
Bowman Mark 13
Remove: Success!
9 nodes
Forwards List
--------------
Bowman John 30
Bowman Frank 37
Bowman David 45
Morales Carlos 68
Christensen Ann 70
Gueller Kathleen 34
Bowman Mark 42
Bowman Richard 47
Cox Susan 36
Backwards List
--------------
Cox Susan 36
Bowman Richard 47
Bowman Mark 42
Gueller Kathleen 34
Christensen Ann 70
Morales Carlos 68
Bowman David 45
Bowman Frank 37
Bowman John 30
|