Stacks and Queues example

I have to make a program that uses the following Unit. I know that you can't provide me with the full source code so I expect just some guidelines not the actual program. Please tell me what the basic structure of the program should be. 10x a lot.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

VGRConnect With a Mentor Commented:
in fact, the stack is a user datatype. It's no more "abstract" than "Extended" IMHO (I mean abstract in opposition to real/instanciated/existent/physical)

Even better, the stack is ***apparently*** not a language construction, while it is : it's the basic data structure that enables you to call a procedure or function, for example. It has to be coded in assembly if ever you write a procedure call or branchment in that language, other example.
It's a native data structure in FORTH, of course

Even worse, files (qtack and queues) structure is built in in almost all processors, from Intel to superscalar ones. It's used in your browser, in your IP communication layers, in your email client, etc
Terry007Author Commented:
I will post the unit in 1 hour. Sorry about that.
well, if Iwere your teacher, I would have done the reverse :
-here's a program using some queues&stacks (LIFO,FIFO files), write the Unit to implement them.

would be funnier
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Terry007Author Commented:
Unit stack1;
   type BaseT=integer;
   const StSize=100;
   function push(x:BaseT):boolean;
   function pop (var x:BaseT) boolean;
  var S:array[1:StSize] of BaseT;
  function push(x:BaseT):boolean;
    if top = StSize then
     push = false else
      begin inc top(top);
  function pop(var x:BaseT):boolean;
    if top:=0 then pop:=false
       x:=S[top]; Dec[top];pop:=true;

This is the unit that has to be used in a program using stack. The book I use ("Learn Pascal" by Sam A. Aboulrouls)
says nothing about that so I'd be glad if you could provide me with some ideas or links that could be usefull.
What are you trying to do with the program?

Basic stack program

if wanting to put something on
  check if stack has room
    push the item on
if wanting to take something off
  check stack has items
    pop it off

Terry007Author Commented:
The problem is that I don't know how can I put this Unit into use. What kind of program could use it. Please give me a simple example.
something like :

program testqueues;
uses stack1;
Var v : BaseT;
  if push(12) Then WriteLn('suceeded in pushing 12 to the stack') Else  WriteLn('failed in pushing 12 to the stack');
  if pop(v) Then Begin
    WriteLn('suceeded in popping from the stack');
    WriteLn('value read = ',v,' (should be 12 ;-)');
  End Else  WriteLn('failed in popping from the stack');
Terry007Author Commented:
10x VGR. Just one more thing. I so the stack is actually an abstract term. I mean it represents the status of a block of memory but it is not part of the language itself. :)
Tha is correct.  A stack is an abstract datatype used for a variety of algorithms.

Most arithmetic is done using stacks.  Operands are pushed onto the stack and popped off when needed by an operator.

Functions and procedures generally pass there parameters using the stack.

You can think of a stack as a last-in first-out data structure.  Information is put on the top and then retrieved from the top.

A queue is similarly an abstract datatype with other uses.  It is a first-in first-out structure.  Information is put in at one end and retrieved from the other.

You can look at a queue as the line at the store.  Everyone starts at the back and slowly moves to the front then gets checked out and moved out of the queue.

A stack is like the dishes at the buffet.  You take them off the top and the staff replaces them on the top.

stack can be used for:

1. remember the history of all websites you have visited, so that when you press Back button, the browser remember where you have visited last time, and you will be brought back to the most recently visited website.

queue can be used for:
1. arrange your email. when your emails come one by one into your mail box, the email software has to arrange them, so that you can see the most recent incoming email appear at the top.

hope u appreciate my examples. if so, please give me points.
All Courses

From novice to tech pro — start learning today.