at the moment this is a stack of queue, i am trying to make it into first in first ou

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 24
Reputation: mel2005 is an unknown quantity at this point 
Solved Threads: 0
mel2005 mel2005 is offline Offline
Newbie Poster

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
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3.  
  4. const int STACK_SIZE = 6;
  5. const int NIL = -1;
  6. const int LAST_ELEMENT = STACK_SIZE - 1;
  7.  
  8. struct stackType
  9. {
  10. int tos;
  11. char data[STACK_SIZE];
  12. };
  13.  
  14.  
  15.  
  16. void create(stackType&);
  17. bool full(stackType);
  18. bool empty(stackType);
  19. void Push(char, stackType& );
  20. void Pop(char&,stackType& );
  21. void Top( char&, stackType);
  22.  
  23. void display(stackType);
  24.  
  25. void create(stackType& s)
  26. {
  27. s.tos = NIL;
  28. }
  29.  
  30. bool full(stackType s)
  31. {
  32. if(s.tos == LAST_ELEMENT)
  33. return true;
  34. else
  35. return false;
  36. }
  37.  
  38. bool empty(stackType s)
  39. {
  40. if (s.tos == NIL)
  41. return true;
  42. else
  43. return false;
  44. }
  45.  
  46. void Push(stackType& s, char achar)
  47. {
  48. s.tos = s.tos + 1;
  49. s.data[s.tos] = achar;
  50. }
  51.  
  52. void Pop(stackType& s, char& achar)
  53.  
  54. {
  55. achar = s.data[s.tos];
  56. s.tos = s.tos + 1;
  57. }
  58.  
  59. void display(stackType s)
  60. {
  61. int i;
  62. for (i = s.tos; i != NIL; i++)
  63. cout << s.data[i] << endl;
  64. }
  65.  
  66. void Top(stackType s, char& achar)
  67. {
  68. achar = s.data[s.tos];
  69. }
  70.  
  71. void main()
  72. {
  73. stackType aStack[3];
  74.  
  75. char command, letter;
  76. int use_stack = 0;
  77. system("cls");
  78.  
  79. for (int i = 0 ; i<3 ; i++) create(aStack[i]);
  80.  
  81. cout << "This program uses a stack implemented as an array\n";
  82. cout << "Maximum number of items = " << STACK_SIZE << endl;
  83.  
  84. do
  85. {
  86. cout << "\nMAKING USE OF STACK " << use_stack;
  87. cout << "\n[P]ush data, P[O]p data, [T]op show top data";
  88. cout << "\n[D]isplay stack, [S]witch stack or [Q]uit -> ";
  89. cin >> command;
  90. switch(command)
  91. {
  92. case 'p' :
  93. case 'P' : if(!full(aStack[use_stack]))
  94. {
  95. cout << "Enter data -> ";
  96. cin >> letter;
  97. Push(aStack[use_stack],letter);
  98. }
  99. else
  100. cout << "The stack is full data not pushed\n";
  101. break;
  102. case 'o' :
  103. case 'O' : if (!empty(aStack[use_stack]))
  104. {
  105. Pop(aStack[use_stack], letter);
  106. cout << letter << " has been popped\n";
  107. }
  108. else
  109. cout << "Stack empty cannot pop\n";
  110. break;
  111. case 't' :
  112. case 'T' : if (!empty(aStack[use_stack]))
  113. {
  114. Top(aStack[use_stack], letter);
  115. cout << letter << " is on top of the stack\n";
  116. cout << "\n";
  117. }
  118. else
  119. cout << "Stack empty cannot pop\n";
  120. break;
  121. case 's' :
  122. case 'S' : do
  123. {
  124. cout << "Which stack do you wish to use (0-2) ";
  125. cin >> use_stack;
  126. } while (use_stack < 0 || use_stack > 2);
  127. break;
  128. case 'd' :
  129. case 'D' : if (!empty(aStack[use_stack]))
  130. display(aStack[use_stack]);
  131. else
  132. cout << "stack empty no data to display\n";
  133. break;
  134. case 'q' :
  135. case 'Q' : cout << "Program terminated\n";
  136. break;
  137. default : cout << "Unknown command [" <<command << "] try again!\n";
  138. break;
  139. }
  140. } while (!(command == 'q' || command == 'Q'));
  141. }
Code tags added. -Narue
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1
Reputation: aman_yadav11 is an unknown quantity at this point 
Solved Threads: 0
aman_yadav11 aman_yadav11 is offline Offline
Newbie Poster

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
i have read your post of c and c++ . this post increase my c and c++ foundamental knowledge and i am thankful to your resoruces and organisation.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,596
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 712
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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
So you have a stack of queues and you want to convert it to a queue of queues?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 24
Reputation: mel2005 is an unknown quantity at this point 
Solved Threads: 0
mel2005 mel2005 is offline Offline
Newbie Poster

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
yes, the right, please help
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 24
Reputation: mel2005 is an unknown quantity at this point 
Solved Threads: 0
mel2005 mel2005 is offline Offline
Newbie Poster

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
hello everyone, just to let you know, i don't need help on this thread, i've done it, took me all night. anywhere thanks, have you got any idea how i can remove this thread
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

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
can you not post up the correct code? It may be of some help to others?
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 24
Reputation: mel2005 is an unknown quantity at this point 
Solved Threads: 0
mel2005 mel2005 is offline Offline
Newbie Poster

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
yes, so i can, i will most probably post it by tommorrow, and i will also post my final piece soon. all i need to do now it switch to different queues, and that the hard bit
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC