Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement as Stack Class using the List Class you developed earlier. To test you

ID: 3650543 • Letter: I

Question

Implement as Stack Class using the List Class you developed earlier. To test your Stack class by determining if the following strings have matching open and closing (), and/or [], and or {}. Use the following to test your code:
()
[](){}
[{()}]
[[))
{()[()]}

Implement a Queueu class using the List Class you developed earlier. Test your Queue class by determining if the following strings are char-by-char palindromes.
ABCDEDCBA
NOTAPALINDROME
ISAPALINILAPASI
2A3MEAS
ATOYOTA
(({}[][]{}((

Note about your List class. You developed a List class using ET(element type) for the data type stored in the array(List). Now the above you will need to change the typedef of ET from int to char. Be sure not to change the ints that deal with position, size, ect. You can use a file for input strings. Save the output file as StackStr.txt for the stack and QStr.txt for the queue program.

Previous list class:
class List
{
public:
//Typedef declarations
typedef int ET;//Element Type
static const ET CAPACITY = 20; //Size of the array

//Constructor
List();

//Class Member Functions
bool empty();
void front();
void end();
void prev();
void next();
int getPos();
void setPos(ET);
bool insertBefore(ET);
bool insertAfter(ET);
int getElement();
int size();
void replace(ET);
void erase();
void clear();
void reverse();
void swap(List &CurrentList);
bool operator==(List &);

//Friends
friend ostream &operator<<(ostream &out, const List &l);

private:
ET MyAry[CAPACITY];
ET Position; //Points current position
ET Used; //Points to next available position
};
//********End Class Definitions/Funtion Prototypes********

//Declare file streams
ofstream outFile;

//Operator Overloads
List operator+(const List &a, const List &b);

int main()
{



//Exit program
return EXIT_SUCCESS;
}


//**********Function Definitions**********
List::List()
{
//Set to zero
Position = 0;
Used = 0;

//Zero out array
for(int i = 0; i < CAPACITY; i++)
{
MyAry[i] = 0;
}
}

bool List::empty()
{
//Used = 0 is returns true
return Used;
}

void List::front()
{
//Sets position to the first location
Position = 0;
}

void List::end()
{
//Gets the end position
if(Used != 0)
{
Position = Used - 1;
}
}

void List::prev()
{
//Subtracts one from current position
if(Position - 1 >= 0)
{
Position--;
}
}

void List::next()
{
//Adds one to current position
if(Position + 1 < Used)
{
Position++;
}
}

int List::getPos()
{
//Returns current Position
return Position;
}

void List::setPos(ET NewPos)
{
//Sets Position to New Position
if((NewPos >= 0) && (NewPos < Used))
{
Position = NewPos;
}
}

bool List::insertBefore(ET value)
{
//Checks for position out of bounds
if(Position + 1 > CAPACITY)
{
return false;
}
else
{
//If used is zero then first element
if(Used == 0)
{
MyAry[Used] = value;
}
else
{
//Shuffles everything down to make room for new element
for(int i = Used; i > Position; i--)
{
MyAry[i] = MyAry[i - 1];
}
MyAry[Position] = value;
}

Used++;

return true;
}
}

bool List::insertAfter(ET value)
{
//Checks for position out of bounds
if(Position + 1 > CAPACITY)
{
return false;
}
else
{
//If used is zero then first element
if(Used == 0)
{
MyAry[Used] = value;
}
else
{
//Moves everything down to make room for new element
for(int i = Used; i > Position + 1; i--)
{
MyAry[i] = MyAry[i - 1];
}
MyAry[Position] = value;
}

//Increment
Position++;
Used++;

return true;
}
}

int List::getElement()
{
//Returns element at Position
return Position;
}

int List::size()
{
//Returns size of the array
return Used;
}

void List::replace(int RepVal)
{
//Replace current value at position with new value
MyAry[Position] = RepVal;
}

void List::erase()
{
//Move all remaining elements down
for(int i = Position; i < Used; i++)
{
MyAry[i] = MyAry[i + 1];
}

//Decrement Used
Used--;
}

void List::clear()
{
//Return the List back to zero
for(int i = 0; i < CAPACITY; i++)
{
MyAry[i] = 0;
}

//Return values to zero
Position = 0;
Used = 0;
}

void List::reverse()
{
// Create temporary holder
List temp;

// Populate temp list with current list
for (int i = 0; i < Used; i++)
{
temp.MyAry[i]= MyAry[i];
}

// Repopulate current list
const int lastIdx = Used-1 ;
for (int i=0; i < Used; ++i)
{
MyAry[i] = temp.MyAry[lastIdx-i] ;
}
}

void List::swap(List &CurrentList)
{
// Create temporary holder
List temp;

// Populate temp list with current list
for (int i = 0; i < CAPACITY; i++)
{
temp.MyAry[i]= MyAry[i];
}

// Replace current list with other list
for (int i = 0; i < CAPACITY; i++)
{
MyAry[i] = CurrentList.MyAry[i];
}

// Replace second list with temp list (first list)
for (int i = 0; i < CAPACITY; i++)
{
CurrentList.MyAry[i] = temp.MyAry[i];
}
}

ostream &operator<<(ostream &outs, const List &s)
{
for(int i = 0; i < s.Used; i++)
{
outs << s.MyAry[i] << " ";
}

return outs;
}

bool List::operator ==(List &l)
{
if(Used == l.size()
&&
MyAry[0]==l.MyAry[0]
&&
MyAry[(Used-1)]==l.MyAry[(Used-1)])
{return 1;}
else
{return 0;}
}

List operator +(const List &L1, const List &L2)
{
List answer;

answer = L1 + L2;

return answer;
}

Explanation / Answer

class List { public: //Typedef declarations typedef int ET;//Element Type static const ET CAPACITY = 20; //Size of the array //Constructor List(); //Class Member Functions bool empty(); void front(); void end(); void prev(); void next(); int getPos(); void setPos(ET); bool insertBefore(ET); bool insertAfter(ET); int getElement(); int size(); void replace(ET); void erase(); void clear(); void reverse(); void swap(List &CurrentList); bool operator==(List &);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote