소개글
샤니의 자료구조론 연습문제풀이입니다.
목차
없음
본문내용
chapter 7. No.1
Develop the C++ class SortedList that uses a formula-based representation. Provide the same member functions as provided in the class SortedChain. Write code for all functions and test the code using suitable test data.
sol)
SortedList 클래스 정의 부분
template<class E, class K>
class SortedList {
public:
SortedList(int MaxListSize = 10); // constructor
~SortedList() {delete [] element;} // destructor
bool IsEmpty() const {return length == 0;}
int Length() const {return length;}
bool Search(const K& k, E& e) const;
SortedList<E,K>& Delete(const K& k, E& e);
SortedList<E,K>& Insert(const E& e);
SortedList<E,K>& DistinctInsert(const E& e);
void Output(ostream& out) const;
private:
int length;
int MaxSize;
E *element; // dynamic 1D array
};
template<class E, class K>
SortedList<E,K>::SortedList(int MaxListSize)
{
MaxSize = MaxListSize;
element = new E [MaxSize];
length = 0;
}
참고 자료
[샤니][자료구조]