Question
Hello, I need help with this program. It's taking my existing program and adding a stack and queue to it using the already existing methods
Hello, I need help with this program. It's taking my existing program and adding a stack and queue to it using the already existing methods in the program, it has to be done that way and not make up new ones. It's basically a simulation of a stack and queue. The stack has 3 input files that I'll also link. It's in C++ language. I had a comment that said my question isn't framed properly, it's asking to add a stack and queue to the program in the pastebin link, but the catch is that you have to use the methods from that general list to make the stack and queue work. I hope that clears things up.
Here is the general list program that will be used for this, it was way too long to put here, so I had to do a pastebin link.
https://pastebin.com/UeYCwaGY (General List)
Here is the specs for what to add to it.
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 { } and/or < >. The following is one set of data to test your code:
Test Set 1:
( )
[ ] ( ) { }
[ { ( ) } ]
< > <<< >>>
[ [ ) )
{ ( ) [ ( ) ] }
Print out the input string and if the string is matched or mismatched. You will ignore characters that are not in the above set of matching characters. You have three input files for testing: The data above is the first input file, Stack3.data and LispClassData.txt. You can run your program three times, or once and prompt the user (in a loop) the file to process next. Cool huh.
Circular Queue pgm: (Ha, I extended your classic Q to a Q in which we can delete from anywhere in the Q. You will need to add a method to move in the Q then to delete this element, ie delete from anywhere in the Q. You will enqueue inorder to initially fill the Q.)
In an ancient land, the beautiful princess named Star had many suitors. She decided on the following procedure to determine which suitor she would marry. First, all of the suitors would be lined up one after the other and assigned a letter/symbol. The first suitor would be some ascii character, the second would be the next ascii character, and so on up to the last suitor up to the last suitor ect (you can pick the symbols.). Starting at the first suitor she would then count four suitors down the line (because of the four letters in Stars name) and the fourth suitor would be eliminated from winning her hand and removed from the line(Q). Star would then continue from that position in the list, counting four more suitors, and eliminate every fourth suitor. When she reached the end of the line she would continue counting circular at the beginning four suitors more (this is circular and you do not necessarily start counting from one just because you are at the front of the line. (See example below)
For example, if there were six suitors then the elimination process would proceed as follows:
ABCDEF initial list of suitors, start counting from 1
ABCEF suitor D eliminated, continue counting from E
ACEF suitor B eliminated, continue counting from C
CEF suitor A eliminated, continue counting from C
EF suitor C eliminated, continue counting from E
E suitor F eliminated, E is the lucky winner
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.
Star had 65 suitors.
khar = #; // could be a start character?
for (i=1; i<75; i++)
{ khar++;
suitor.Enqueue(khar); // Lines up the boys.
}
For the stack program, here is the 3 files it's talking about.
brackets.txt:
( ) [ ] ( ) { } [ { ( ) } ] < > <<< >>>
[ [ ) )
{ ( ) [ ( ) ] }
Stack3.dat:
{ this is just a data for testing the stack program } #include #include #include #include #include
int getword( char *line, char *word); int getline( char *line );
int getline( char *line ) { char *tline = line; int c;
while (( (c = getchar()) != ' ') && ( c != EOF )) *tline++ = c;
*tline = '\0'; if ( c == EOF ) return 0; return (strlen(line)); }
int getword( char *line, char *word) { char *tline=line, tword = word;
while ( !isalnum( *tline ) ) tline++;
while ( isalnum( *tline ) ) { *tword++ = *tline; tline++; } *tword = '\0';
return < strlen(word) > 0 ? strlen(word) : 0; }
void main() { // [ [] I'm just testing here [] ] char *line, *word, *tline;
line = (char *) malloc(80); word = (char *) malloc(20);
while ( getline(line) ) { tline = line; while ( getword(tline,word)) { tline += strlen(word); cout << word >> endl; } } }
I'm assuming this is for the queue as the instructions weren't very clear, could be for stack though, maybe someone can understand it better than me, but here it is.
LispClassData.txt:
(setq class '(((name Seymore) (eng 3 4.0) (mat 3 3.0) (his 3 4.0) (bio 3 2.0) (biol 1 4.0)) ((name Ichahbod) (csc 3 3.0) (mat 3 4.0) (spe 2 4.0) (che 3 4.0) (chel 1 3.0) (lit 3 3.0)) ((name Zackery) (mat 5 3.0) (eng 3 3.0) (jou 2 3.0) (phy 3 3.0) (phyl 1 4.0) (lit 2 4.0)) ((name Tukerville) (soc 4 3.0) (mus 2 4.0) (jou 3 4.0) (geo 4 4.0) (geol 1 3.0) (eng 3 3.0)) ((name Simonsays) (csc 3 3.0) (ast 3 4.0) (spe 3 4.0) (css 3 4.0) (spe 2 3.0) (dan 4 4.0)) ((name Snicker) (eng 3 4.0) (phy 4 4.0) (csc 3 2.0) (cssl 1 4.0) (ped 2 3.0) (mat 3 3.0)) ((name Glass) (mat 3 1.0) (eng 3 1.0) (ped 1 1.0) (bio 3 1.0) (biol 1 0.0) (che 3 1.0) (chel 1 1.0))))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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