00001 #ifndef SEQUENCE_IMPLEMENTATION
00002 #define SEQUENCE_IMPLEMENTATION
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "array.cpp"
00019 #include "function.h"
00020 #include "guards.h"
00021 #include "sequence.h"
00022
00023 template <class contents>
00024 int sequence<contents>::comparator(const sequence &s2) const
00025 {
00026 if (!this->length() && !s2.length()) return 0;
00027 for (int i = 0; i < minimum(this->length(), s2.length()); i++) {
00028 if (this->get(i) < s2.get(i)) return -1;
00029 else if (s2.get(i) < this->get(i)) return 1;
00030 }
00031 if (this->length() < s2.length()) return -1;
00032 else if (this->length() > s2.length()) return 1;
00033 else return 0;
00034 }
00035
00036 template <class contents>
00037 int sequence<contents>::find(const contents &to_find, int &position,
00038 outcome &outcome) const
00039 {
00040 outcome = common::OUT_OF_RANGE;
00041 bounds_return(position, 0, this->last(), 0);
00042 for (int i = position; i < this->length(); i++)
00043 if (this->get(i) == to_find) {
00044 position = i;
00045 outcome = common::OKAY;
00046 return i;
00047 }
00048 outcome = common::NOT_FOUND;
00049 return 0;
00050 }
00051
00052 template <class contents>
00053 int sequence<contents>::find(const sequence &to_find, int &position,
00054 outcome &outcome) const
00055 {
00056 outcome = common::OUT_OF_RANGE;
00057 bounds_return(position, 0, this->length() - to_find.length(), 0);
00058
00059
00060 for (int i = position; i < this->length() - to_find.length() + 1; i++) {
00061 sequence<contents> chopped = this->subarray(i, i + to_find.last());
00062 if (chopped == to_find) {
00063 position = i;
00064 outcome = common::OKAY;
00065 return i;
00066 }
00067 }
00068 outcome = common::NOT_FOUND;
00069 return 0;
00070 }
00071
00072 #endif
00073