[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

A question about 'queues'

Posted on 1998-10-27
4
Medium Priority
?
281 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Sometimes Administrators rights are not enough. These cases call for the SYSTEM account. The process in this article outlines the steps required to execute commands using the SYSTEM account.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
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…

650 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