Header File for List ADT - Array Implementation


// *********************************************************
// Header file ListA.h for the ADT list.
// Array-based implementation.
// *********************************************************
#ifndef ARRLIST_H
#define ARRLIST_H

const int MAX_LIST = 50;
typedef int listItemType;

class List
{
public:
	List(); 		 // default constructor
				 // destructor is supplied by compiler

// list operations:
	int isEmpty() const;
	// Determines whether a list is empty.
	// Precondition: None.
	// Postcondition: Returns true if the list is empty,
	// otherwise returns false.

	int length() const;
	// Determines the length of a list.
	// Precondition: None.
	// Postcondition: Returns the number of items
	// that are currently in the list.

	int insert(int NewPosition, listItemType NewItem);
	// Inserts an item into a list.
	// Precondition: NewPosition indicates where the
	// insertion should occur. NewItem is the item to be
	// inserted.
	// Postcondition: If insertion was successful, NewItem is
	// at position NewPosition in the list, other items are
	// renumbered accordingly, and returns true;
	// otherwise returns false.
	// Note: Insertion will not be successful if
	// NewPosition < 1 or > ListLength()+1.

	int del(int Position);
	// Deletes an item from a list.
	// Precondition: Position indicates where the deletion
	// should occur.
	// Postcondition: If 1 <= Position <= ListLength(),
	// the item at position Position in the list is
	// deleted, other items are renumbered accordingly,
	// and returns true; otherwise returns false.

	int retrieve(int Position, listItemType& DataItem) const;
	// Retrieves a list item by position number.
	// Precondition: Position is the number of the item to
	// be retrieved.
	// Postcondition: If 1 <= Position <= ListLength(),
	// DataItem is the value of the desired item and
	// returns true; otherwise returns false.

private:
	listItemType Items[MAX_LIST];  // array of list items
	int          Size;             // number of items in list

	int index(int Position) const;
	// Converts the position of an item in a list (1,...,length()) to the
	// correct index within its array representation (0,...,length()-1).
};  // end class

#endif
// End of header file.


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page