Lecture 8

Listclasslistclass this destructor does nothing 13

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } This is required by C++ and not part of our abstraction. listClass::~listClass() { } // This destructor does nothing 13 Insert(L, i, newitem) listClass::Insert(int i, ItemType newitem, boolean& success) { int L_pos = Length( ); success = boolean( ( i >= 1) && (i <= L_pos + 1) && (L_pos < MAX_LIST) ); if (success) { // !!!!! Insert newitem (see next page) ++Size; } } 14 Array Insertion (missing part from last page) for (int position = L_pos; position >= i; --position) Items[Index(Position+1)] = Items[Index(Position)]; Items[Index(i+1)] = newitem; Note that function Index( ) returns position-1. int listClass::Index(int Position) {return Position-1;) 15 void listClass::Delete(int i, boolean& success) { int L_pos = Length( ); success = boolean( (i >= 1) && (i <= L_pos) ); if (success) { for (int From_pos = i+1; From_pos <= L_pos; ++From_pos) Items[Index(From_pos-1)] = Items[Index(From_pos); --Size; } 17 } 16 Retrieve(L, i, Item) void listClass::Retrieve(int i, ItemType& Item, boolean& success) { int L_pos = Length( ); success = boolean( ( i >= 1) && (i <= L_pos) ); if (success) Item = Items[Index(i)]; } 18...
View Full Document

Ask a homework question - tutors are online