Question

Stack Queue Program Implement a Stack class using the List Class you developed earlier. Test your...

Stack Queue Program

Implement a Stack class using the List Class you developed earlier. Test your Stack class by determining if the following strings have matching open and closing ( ) and/or [ ] and/or { }. To test matches, push open (, [, { onto the stack. Input a close char, pop off the stack and see if input matches symbol form stack.   Use the following data to test your code:

                              ( )

                              [ ] ( ) { }

                              [ { ( ) } ]

                              [ [ ) )

                              [ ( ) ] ] [

                              ( ( ( ) ) ) [ ( ) ( ) ]

                              { ( ) [ ( ) ] }

Print out the input string and if the string is matched or mismatched.

Implement a Queue class using the List Class you developed earlier. Test your Queue class by determining if the following strings are char-by-char palindrome. To test for a palindrome, you will used both a stack and a queue data structure.

                              ABCDEDCBA

                              NOTAPALINDROME

                              ISAPALINILAPASI

                              2A3MEAS

                              ATOYOTA

                              (({}[][]{}((

                              Tattarrattat

                              racecar

Note about your List class. You developed you List class (I hope) 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. If you have a good class development, then this should be one line change, if not, you will have several ints to change. Be sure NOT to change the ints that deal with position, size etc. just the data type stored in the list.

You can use a file for input of your strings. You may save this spec sheet to a file and then edit it and leave only the data strings. Save file as StackStr.txt. Do the same thing again and save the QStr.txt for the queue program.

Homework Answers

Answer #1

#include <iostream>

#include <stack>

using namespace std;

void balance_parentheses();

int main()

{

int t;

cout << "Enter :";

cin >> t;

for (int i = 0; i < t; i++) {

balance_parentheses();

}

return 0;

}

void balance_parentheses()

{

stack<char> test;

string P;

cout << "Enter parentheses:";

cin >> P;

int flag = 0;

for (int i = 0; i < P.length(); i++)

{

if (P[i] == '{' || P[i] == '[' || P[i] == '(') {

test.push(P[i]);

flag = 1;

}

if (!test.empty()) {

if (P[i] == '}') {

if (test.top() == '{')

{

test.pop();

continue;

}

else

break;

}

if (P[i] == ']') {

if (test.top() == '[') {

test.pop();

continue;

}

else

break;

}

if (P[i] == ')') {

if (test.top() == '(') {

test.pop();

continue;

}

else

break;

}

}

else {

break;

}

}

if ((test.empty()) && (flag == 1))

cout << "YES" << endl;

else

cout << "NO" << endl;

}

//////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....
Write a C program: Implement the abstract data type (ADT) queue (FIFO) of strings. ADT has...
Write a C program: Implement the abstract data type (ADT) queue (FIFO) of strings. ADT has the following methods: clear – clears the queue; is_empty – returns 1 if the queue is empty, otherwise 0; is_full – returns 1 if the queue is full, otherwise 0; add – adds a new string at the end of the queue; remove – removes the string from the front of the queue. Use ADT queue to solve the following problems: • Write an...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty queue,...
python problem: ( use a loop to read each character from the string and insert into...
python problem: ( use a loop to read each character from the string and insert into the stack) 1. The function main a5.py continually asks the user for a string, and calls isPalindrome to check whether each string is a palindrome. A palindrome is a word or sequence that reads the same backward as forward, e.g., noon, madam or nurses run. 2. Your function must ignore spaces: when the user enters 'nurses run', the function returns True, to indicate that...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
IN JAVA Language- Singly Linked List Implementation Implement a Linked List in your language. Use your...
IN JAVA Language- Singly Linked List Implementation Implement a Linked List in your language. Use your Can class. You need to create a driver that makes several Can objects and places them in alphabetical order in a list. Identify the necessary methods in a List Linked implementation. Look at previous Data Structures (stack or queue) and be sure to include all necessary methods. NOT USE your language's Library List . You will receive zero points. Write a LinkedList class. Include...
c++ just one file for all of it. You are to implement a 'list' class to...
c++ just one file for all of it. You are to implement a 'list' class to handle a list with general operations. That means you can insert and delete any element anywhere in the list. your list will be an array. the list has no order, except for the order you insert or delete. The methods you are to implement are as given: constructor methods (two, default and copy constructor, a list to a newly defined list, ie 'list listA(listB)')...
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy....
Implement and demonstrate a disk-based buffer pool class based on the LRU buffer pool replacement strategy. Disk blocks are numbered consecutively from the beginning of the file with the first block numbered as 0. Assume that blocks are 4096 bytes in size. Use the supplied C++ files to implement your LRU Buffer Pool based on the instructions below. • Implement a BufferBlock class using the supplied BufferBlockADT.h o Your Buffer Block must inherit BufferBlockADT or you will not get credit...
Write in Java (Not Javascript) Provide an implementation of priority queue using double-ended doubly linked lists....
Write in Java (Not Javascript) Provide an implementation of priority queue using double-ended doubly linked lists. Recall that double-ended means keeping first and last references and doubly linked feature allows us to go backwards, using a prev reference at each Link. Also, note that the greater the number, the lower the priority. For instance, 2 is of higher priority compared to 5. Specifically, write a class LinkedListPriorityQ which implements the priority queue methods: boolean isEmpty() void enqueue(int item) int dequeue()...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue...
You must alter the Queue class you created in L5 to make it a CIRCULAR Queue class . Call your class Queue. it must be a template class. public class Queue { } I have put a driver program in the module . It is called CircularQueue.java This driver program should then run with your Queue class (no modifications allowed to the driver program). Your Queue class should have at least the following methods: one or more constructors, enqueue, dequeue,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT