Solved

A question about 'queues'

Posted on 1998-10-27
4
241 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
  • 3
4 Comments
 

Accepted Solution

by:
Raid earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now