| | |
at the moment this is a stack of queue, i am trying to make it into first in first ou
![]() |
•
•
Join Date: Mar 2005
Posts: 24
Reputation:
Solved Threads: 0
at the moment this is a stack of queue, i am trying to make it into first in first ou
0
#1 Mar 29th, 2005
at the moment this is a stack of queue, i am trying to make it into first in first out, (FIFO) , can anyone help. thank you very much
Code tags added. -Narue
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <stdlib.h> const int STACK_SIZE = 6; const int NIL = -1; const int LAST_ELEMENT = STACK_SIZE - 1; struct stackType { int tos; char data[STACK_SIZE]; }; void create(stackType&); bool full(stackType); bool empty(stackType); void Push(char, stackType& ); void Pop(char&,stackType& ); void Top( char&, stackType); void display(stackType); void create(stackType& s) { s.tos = NIL; } bool full(stackType s) { if(s.tos == LAST_ELEMENT) return true; else return false; } bool empty(stackType s) { if (s.tos == NIL) return true; else return false; } void Push(stackType& s, char achar) { s.tos = s.tos + 1; s.data[s.tos] = achar; } void Pop(stackType& s, char& achar) { achar = s.data[s.tos]; s.tos = s.tos + 1; } void display(stackType s) { int i; for (i = s.tos; i != NIL; i++) cout << s.data[i] << endl; } void Top(stackType s, char& achar) { achar = s.data[s.tos]; } void main() { stackType aStack[3]; char command, letter; int use_stack = 0; system("cls"); for (int i = 0 ; i<3 ; i++) create(aStack[i]); cout << "This program uses a stack implemented as an array\n"; cout << "Maximum number of items = " << STACK_SIZE << endl; do { cout << "\nMAKING USE OF STACK " << use_stack; cout << "\n[P]ush data, P[O]p data, [T]op show top data"; cout << "\n[D]isplay stack, [S]witch stack or [Q]uit -> "; cin >> command; switch(command) { case 'p' : case 'P' : if(!full(aStack[use_stack])) { cout << "Enter data -> "; cin >> letter; Push(aStack[use_stack],letter); } else cout << "The stack is full data not pushed\n"; break; case 'o' : case 'O' : if (!empty(aStack[use_stack])) { Pop(aStack[use_stack], letter); cout << letter << " has been popped\n"; } else cout << "Stack empty cannot pop\n"; break; case 't' : case 'T' : if (!empty(aStack[use_stack])) { Top(aStack[use_stack], letter); cout << letter << " is on top of the stack\n"; cout << "\n"; } else cout << "Stack empty cannot pop\n"; break; case 's' : case 'S' : do { cout << "Which stack do you wish to use (0-2) "; cin >> use_stack; } while (use_stack < 0 || use_stack > 2); break; case 'd' : case 'D' : if (!empty(aStack[use_stack])) display(aStack[use_stack]); else cout << "stack empty no data to display\n"; break; case 'q' : case 'Q' : cout << "Program terminated\n"; break; default : cout << "Unknown command [" <<command << "] try again!\n"; break; } } while (!(command == 'q' || command == 'Q')); }
•
•
Join Date: Feb 2005
Posts: 1
Reputation:
Solved Threads: 0
Re: at the moment this is a stack of queue, i am trying to make it into first in first ou
0
#2 Mar 29th, 2005
Re: at the moment this is a stack of queue, i am trying to make it into first in first ou
0
#3 Mar 29th, 2005
•
•
Join Date: Mar 2005
Posts: 24
Reputation:
Solved Threads: 0
Re: at the moment this is a stack of queue, i am trying to make it into first in first ou
0
#4 Mar 29th, 2005
•
•
Join Date: Mar 2005
Posts: 24
Reputation:
Solved Threads: 0
Re: at the moment this is a stack of queue, i am trying to make it into first in first ou
0
#5 Mar 30th, 2005
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
Re: at the moment this is a stack of queue, i am trying to make it into first in first ou
0
#6 Mar 30th, 2005
•
•
Join Date: Mar 2005
Posts: 24
Reputation:
Solved Threads: 0
Re: at the moment this is a stack of queue, i am trying to make it into first in first ou
0
#7 Mar 31st, 2005
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: parsing date strings mm/dd/yy??
- Next Thread: how to test equality of 2 objects
| Thread Tools | Search this Thread |
action api array auto based beginner binary bitmap c++ c/c++ calculator challenge char class classes code coding compile console conversion count createcopyofanyfileinc delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game garbage givemetehcodez graph gui hmenu homeworkhelp homeworkhelper iamthwee ifstream input insert int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node noob output parameter pointer primenumbersinrange problem program programming project python random read recursion reference rpg sockets string strings temperature template test text text-file tree url variable vector video win32 windows winsock wordfrequency wxwidgets






