?
Solved

A question about 'queues'

Posted on 1998-10-27
4
Medium Priority
?
275 Views
Last Modified: 2010-04-16
Hi,
I'm having some difficulty understanding the construction of
queues. The examples in my text are too long for me(4 pages) to gain a full understanding, which is resulting in confusion.

If someone could give me an example of how they are supposed
to be structured(the text has used different structures) along with an example I would greatly appreciate the help.

Also, if you could point me to some literature that explains the reason why pointers are used in some programs and not in other programs that involve queues, I would appreciate that as well.

Best regards,

Pyramid
0
Comment
Question by:Pyramid
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Accepted Solution

by:
Raid earned 150 total points
ID: 1215864
Hello This is Raid:

Okay, you want to understand queues, right?
Well, I will show you an example of a queue, and then show
you my programming example, here they are:

Lets say we have names, and are queue can only fit five:
1:George
2:Bob
3:Lisa
4:Micheal
5:Jason

Now, we want to add a Ryan, so we would add Ryan to the top,
and have everything pushed down, but, since we only want
5 in are queue, we will have to discard the last one, which
in this case, it is Jason:

1:Ryan
2:George
3:Bob
4:Lisa
5:Micheal

Notice, Jason is missing.  Anyway, I will show you how to program
it, now:

uses
 crt, drivers;

var
 count: byte;
 queue: array[1 .. 5] of string;

procedure wait;
var
 keybutton: tevent;
begin
 repeat
  getkeyevent(keybutton);
 until keybutton.keycode <> kbNOKEY;
end;

begin
 clrscr;
 { Define our people in our queue }
 queue[1] := 'George';
 queue[2] := 'Bob';
 queue[3] := 'Lisa';
 queue[4] := 'Micheal';
 queue[5] := 'Jason';
 { print it }
 for count := 1 to 5 do begin
  gotoxy(1, count); writeln(queue[count]);
 end;
 wait;
 { now, we want to add Ryan }
 { so shift everything but the last one down, because
   the last one is going to be discarded anyway }
 { go from the bottom up so nothing gets overwritten }
 for count := 4 downto 1 do begin
  queue[count + 1] := queue[count];
 end;
 queue[1] := 'Ryan'; clrscr;
 { now print the new one }
 for count := 1 to 5 do begin
  gotoxy(1, count); writeln(queue[count]);
 end;
 wait;
 { Simple as that }
end.
0
 

Expert Comment

by:Raid
ID: 1215865
This is Raid:

Sorry to not include this, but about that "some people use
array's and some people use pointers" or something like that.
Well, pointers are used to point at things in memory(hence the name pointers), anyway, you can use arrays for this sort of thing you are dealing with, because they are easier to use.
0
 

Expert Comment

by:Raid
ID: 1215866
Sorry, Raid AGAIN!

About the part of your question about structers, you don't need any structers for this.  If you want structers(Types, or Records)
in that example then contact me at:

arcwolf@mb.sympatico.ca
0
 

Author Comment

by:Pyramid
ID: 1215867
Thanks Raid,

That explains a few problems that I was having but I'll e-mail you the other questions I have.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New style of hardware planning for Microsoft Exchange server.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question