728x90
  • Design and implement (in C++) an ADT Array that can dynamically grow and shrink as integers are data is inserted and removed. // ADT array 을 하나 맏르어줘서 엄청나게 커질수도 작아질수도 있게 만들어 주는거네요 . Access time to any item in an array (via it's index) should be constant. The cost of an insert into the middle of an array may be O(n). Indexes need not start at zero and may be negative.
  1. The ADT should include the following:
    1. -A default constructor that creates an empty array starting at index 0.
    2. -A constructor taking an intdata [] array that builds an array populated with the items in the array starting at index 0.
    3. -A constructor taking a range int low, int high that builds an empty array ranging from the low index to the high. (Pre: high >= low.)
    4. -A copy constructor array( const array& that ) .
    5. -A destructor. 
    6. -An accessor int size( ) that returns the size of (number of entries in) the array. 
    7. -An accessor int find( intdata n ) that returns the index of element n in the array.
    8. -An accessor int at( intdata n ) that returns the integer at the given index n. 
    9. -A mutator void insert( intdata n ) that inserts the element n at the end of the array.
    10. -A mutator void insert( intdata n, index i ) that inserts the element n into the array at index position i. 
    11. -Amutator void erase( int index ) that removes the element at the given index position in the array. 
    12. -A mutator void clear( ) that empties the array.
    13. Overload the [] operator
    14. Overload the assignment operator =
    15. Overload the operator == to test array equality.
    16. Overload the operator != to test array inequality.

ADT란게 자료의 type에 무관하게 사용하겠다는 겁니다. 뎃글에 자료형을 물어보신 글이 있던데 특정한 자료가 정해진 것아닙니다. C++ 문법에 template이 있는데 이 부분은 표준이 제대로 안되어 있어서 컴파일러마다 조금씩 다르기도 합니다.

배열의 크기가 동적으로 커졌다고 줄었다가 한다고 되어 있습니다. 배열로 지정하고 크기에 따라 deep copy를 통해 크기가 다른 배열로 바꿀 수도 있습니다만 문제에서 O(n)이 예상된다고 하니 링크드리스트를 원하는 것으로 보입니다.


한시간 넘게 붙잡고 있었는데 엉망이다. 귀찮아서 다 inline으로 해버렸고
A constructor taking a range int low, int high that builds an empty array ranging from the low index to the high. (Pre: high >= low.)
이부분... 생성자에서 low와 high값을 argument로 던져주고 배열사이즈를 계산해서 생성하란 것 같은데 무슨 뜻인지, 왜 필요한지 몰라서 제대로 못했다.
그리고 test결과 =연산자가 제대로 작동하지 않는다. 제대로 연산은 되는데 const &로 parameter를 맞추니까 오류나고 그냥 해버리니까 연산이 끝난 후 R-value의 링크가 사라진다. 뭐냐고..

아무튼 문제에 보면 Indexes need not start at zero and may be negative. 이렇게 되어 있는데 그러면 생성할 때 배열의 low와 high를 정하는 것이 아니라 method중에 begin을 결정하는 method가 있으면 되는거 아닌가? 문제를 만든 사람은 뭘 생각한 거지? 내 영어실력이 문젠가?
아무튼 제대로 이해한 사람 있으면 좀 알려주..
728x90

'Programming > C++은객체지향언어다' 카테고리의 다른 글

error C2220: warning treated as error - no object file generated  (0) 2011.07.29
g++ for windows  (0) 2008.11.07
집합(차집합, 교집합, 합집합) - cpp  (0) 2008.04.02
C++ (OOP개념들)  (0) 2008.02.26
C++ (객체)  (0) 2008.02.26
C++ (OOP개념)  (0) 2008.02.26
C++ (개요)  (0) 2008.02.26

+ Recent posts