Question
Program 3 Modify Program 2... Implement the LIST using pointers to store data for an unlimited number of integer values. (See review lectures for creating
Program 3 Modify Program 2... Implement the LIST using pointers to store data for an unlimited number of integer values. (See review lectures for creating a LIST using pointers) Write and Run the code... Write your conclusion why it is better or worse the first program, and second program
#include
using namespace std;
class LIST{
private:
int v[11];
int count;
public:
LIST() {
for(int i = 0; i < 11; i++)
v[i] = -1;
count = 0;
}
bool isFull() {
if (count == 11){
return true;
}
else{
return false;
}
}
bool add1(int inVar) {
if (!isFull()) {
count++; // add 1 count
for(int i = 0; i < 11; i++){
if(v[i] == -1){
v[i] = inVar;
return true;
}
}
}
return false;
}
bool isEmpty() {
if (count == 0){
return true;
}
else{
return false;
}
}
bool found(int inVal) {
for(int i = 0; i < 11; i++){
if(v[i] == inVal){
return true;
}
}
return false;
}
bool delete1(int inVal) {
for(int i = 0; i < 11; i++){
if(v[i] == inVal){
v[i] = -1;
return true;
}
}
return false;
}
void listAll() {
cout << "List: ";
for(int i = 0; i < 11; i++){
if(v[i] != -1)
cout << v[i] << " ";
}
cout << endl;
}
void makeEmpty() {
for(int i = 0; i < 11; i++){
v[i] = -1;
}
}
};
int main() {
cout << "Program #1" << endl;
LIST L1;
L1.add1(42);
L1.add1(7);
L1.add1(104);
L1.listAll();
L1.delete1(7);
L1.listAll();
if (L1.found(7)) {
cout << "7 found" << endl;
}
else {
cout << "7 not found" << endl;
}
if (L1.found(42)) {
cout << "42 found" << endl;
} else {
cout << "42 not found" << endl;
}
L1.listAll();
L1.makeEmpty();
L1.listAll();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started