Class Method not working...

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
using namespace std;

const int ARRAYSIZE = 100; 
#define TRUE 1
#define FALSE 0
#define DataType int
typedef int 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();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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 - 1; j++ )
			{
				listitem[j] = listitem [ j + 1 ];
			}
			size--;
			break;
		}
	}
}
That makes sense and needs to be changed but item is still not making it inside the if loop?
It was the break point. I see. Thank you.
Last edited on
Topic archived. No new replies allowed.