The void SeqList::Delete( const DataType& item ) Method is the one in question. I've tried debugging, it appears the number is not making it inside the for loop. I don't know how to fix?
#include <iostream>
usingnamespace std;
constint ARRAYSIZE = 100;
#define TRUE 1
#define FALSE 0
#define DataType int
typedefint Boolean;
class SeqList {
private:
// list storage array and number of current list elements
DataType listitem[ARRAYSIZE];
int size;
public:
// constructor
SeqList(void);
// list access methods
int ListSize(void) const;
Boolean ListEmpty(void) const;
Boolean Find (DataType& item) const;
DataType GetData (int pos) const;
void PrintList(void) const;
// list modification methods
void Insert (const DataType& item);
void Delete (const DataType& item);
DataType DeleteFront (void);
void ClearList (void);
};
SeqList::SeqList(){ // sets the size of the list to 0
size = 0;
}
int SeqList::ListSize(void) const { // returns the size of the list
return size;
}
Boolean SeqList::ListEmpty(void) const {
if ( size == 0 ) return TRUE;
if ( size > 0 ) return FALSE;
}
void SeqList::Insert( const DataType& item ) {
listitem[size++] = item;
}
void SeqList::ClearList() {
while (size-- > 0 ) listitem[size] = 0;
}
Boolean SeqList::Find (DataType& item) const {
int find = item;
for ( int i = 0; i <= size; i++) {
if ( find == listitem[i] ) {
return TRUE;
break;
}
}
return FALSE;
}
void SeqList::Delete( const DataType& item ) {
cout << item;
for ( int i = 0 ; i <= size ; i++) {
if ( item == listitem [i] ) {
cout << item ;
for ( int j = i ; j < size; j++ ) {
listitem[j] = listitem [ j + 1 ];
}
size--;
}
break;
}
}
DataType SeqList::DeleteFront(){
int C = listitem[0];
if (size != 0 ) {
for ( int i = 0 ; i <= size ; i++) {
listitem [i] = listitem [ i + 1 ];
}
listitem[size] = 0;
size--;
}
return C;
}
void SeqList::PrintList() const {
for ( int i = 0 ; i < size ; i++) {
cout << (i+1) << ". " << listitem[i] << endl;
}
}
DataType SeqList::GetData(int pos) const {
int G = pos;
if ( G < 0 ) cout << " This Position is outside of list bounds. " << endl;
return 0;
if ( G > size ) cout << " This Position is outside of list bounds. " << endl;
return 0;
return listitem[G];
}
int main () {
SeqList one; // creates a list instance named one
one.Insert(678687);
one.Insert(98009);
one.Insert(789);
one.Insert(908);
one.Insert(6759);
cout << "The size of the list is:" << one.ListSize() << endl;
cout << "The list is empty?:" << one.ListEmpty() << endl;
int number = 789;
int number2 = 874;
cout << "find the number 789 in the list please." << one.Find(number) << endl;
cout << "find the number 874 in the list please." << one.Find(number2) << endl;
one.PrintList();
one.Delete(number);
cout << "The size of the list is:" << one.ListSize() << endl;
cout << "The list is empty?:" << one.ListEmpty() << endl;
one.PrintList();