00001 const int LIST_SIZE = 10;
00002
00003 template <class Elem>
00004 class List {
00005 private:
00006 int msize;
00007 int numinlist;
00008 int curr;
00009 Elem* listarray;
00010 public:
00011 List(int =LIST_SIZE);
00012 ~List();
00013 void clear();
00014 void insert(const Elem);
00015 void append(const Elem);
00016 Elem remove();
00017 void setFirst();
00018 void prev();
00019 void next();
00020 int length() const;
00021 void setPos(int);
00022 void setValue(const Elem);
00023 Elem currValue() const;
00024 bool isEmpty() const;
00025 bool isInList() const;
00026 bool find(int);
00027 };
00028
00029 template <class Elem>
00030 List<Elem>::List(int sz) {
00031 msize = sz; numinlist = curr = 0;
00032 listarray = new Elem[sz];
00033 }
00034
00035 template <class Elem>
00036 List<Elem>::~List()
00037 { delete [] listarray; }
00038
00039 template <class Elem>
00040 void List<Elem>::clear()
00041 { numinlist = curr = 0; }
00042
00043
00044 template <class Elem>
00045 void List<Elem>::insert(const Elem item) {
00046
00047 assert((numinlist < msize) && (curr >=0)
00048 && (curr <= numinlist));
00049 for(int i=numinlist; i>curr; i--)
00050 listarray[i] = listarray[i-1];
00051 listarray[curr] = item;
00052 numinlist++;
00053 }
00054
00055 template <class Elem>
00056 void List<Elem>::append(const Elem item) {
00057 assert(numinlist < msize);
00058 listarray[numinlist++] = item;
00059 }
00060
00061 template <class Elem>
00062 Elem List<Elem>::remove() {
00063 assert(!isEmpty() && isInList());
00064 Elem temp = listarray[curr];
00065 for(int i=curr; i<numinlist-1; i++)
00066 listarray[i] = listarray[i+1];
00067 numinlist--;
00068 return temp;
00069 }
00070
00071 template <class Elem>
00072 void List<Elem>::setFirst()
00073 { curr = 0; }
00074
00075 template <class Elem>
00076 void List<Elem>::prev() { curr--; }
00077
00078 template <class Elem>
00079 void List<Elem>::next() { curr++; }
00080
00081 template <class Elem>
00082 int List<Elem>::length() const
00083 { return numinlist; }
00084
00085 template <class Elem>
00086 void List<Elem>::setPos(int pos)
00087 {curr = pos; }
00088
00089
00090 int main() {
00091 List<int> L1(15);
00092 List<double> L2;
00093
00094 L1.append(12);
00095 L2.append(12.0);
00096 }