Solved

A question about 'queues'

Posted on 1998-10-27
4
272 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 50 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Multi-threading long-running processes can have a significant increase in overall performance and drastically decrease over time it takes for a process to complete. Unfortunately, not all applications support native multi-threading, some by design a…
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 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