Take the 2008 Git User's Survey and help out! [ hide ]

public
Description: Homework assignments for CSC 393 Data Structures In C++.
Clone URL: git://github.com/josh/csc_393.git
Search Repo:
Added test suite for OrderedList.
josh (author)
Sun Apr 20 18:35:04 -0700 2008
commit  53c5410e1df2d1221a0605d884ec23d7c93e20a5
tree    b8d401be0361df65087151fc1920e4d66df7a3b8
parent  4c0820a2219fa717eadc6663d22760358d60cc2d
...
29
30
31
 
 
32
33
34
...
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
...
29
30
31
32
33
34
35
36
...
45
46
47
 
 
 
 
 
 
48
49
50
51
52
53
54
 
 
 
 
 
55
56
57
58
59
60
61
 
62
63
64
65
66
67
68
0
@@ -29,6 +29,8 @@ using namespace std;
0
 template <typename Object>
0
 class OrderedList {
0
 public:
0
+ typedef typename list<Object>::const_iterator listObjectIterator;
0
+
0
   OrderedList() {
0
     orderedList = list<Object>(128);
0
   }
0
@@ -43,29 +45,24 @@ public:
0
   // insert, which takes a single Object parameter and inserts that value into
0
   // the proper location in the list
0
   void insert(Object i) {
0
- for(int j = 0; j < orderedList.size(); j++) {
0
- if (orderedList[j].empty() || i <= orderedList[j]) {
0
- orderedList.insert(orderedList.begin()+j, 1, i);
0
- return;
0
- }
0
- }
0
     orderedList.push_back(i);
0
+ orderedList.sort();
0
   }
0
 
0
   // remove, which takes a single Object parameter and finds and removes the
0
   // first occurrence of that value in the list
0
   void remove(Object i) {
0
- for(int j = 0; j < orderedList.size(); j++) {
0
- if(i == orderedList[j]) {
0
- orderedList.erase(orderedList.begin()+j, orderedList.begin()+j+1);
0
- }
0
- }
0
+ orderedList.remove(i);
0
+ orderedList.sort();
0
   }
0
 
0
   // operator[], that is, overload the [] operator so that one can directly
0
   // index values in the ordered list
0
   const Object & operator[](int i) const {
0
- return orderedList[i];
0
+ listObjectIterator it = orderedList.begin();
0
+ for (int j = 0; j < i; j++)
0
+ it++;
0
+ return *it;
0
   }
0
 
0
   // size, which takes no parameters and returns the size of the list

Comments

    No one has commented yet.