Program Queue Pascal !EXCLUSIVE!
Click Here ===== https://urllio.com/2t0xj3
Hi all :-) I am making a program about queues that will enable the user to add, view and delete data from the queue with out the user of pointers. So far I have coded the following code but I need some advice on what to do next. I have already had some advice from some people but unfortunately they all refered to pointers. My Computing A-level book also seems to give the impression that the queues program is possible without pointers e.g. ^nodeptr. Anyway here is the code so far and thanks in advance:- program queues; uses crt; {Shiva Naicken} const limit = 10; type queue = record item : array [1..limit] of string; front:integer; rear:integer; size:integer; end; var q:queue; choice : integer; procedure initialise; begin q.front:=0; q.rear:=0; q.size:=0; end; procedure view; var loop:integer; begin clrscr; for loop:=1 to limit do writeln (q.item[loop]); end; procedure add; var data : string; begin writeln('Input the data to be placed in the queue: '); readln(data); with q do if q.size = limit then writeln('QUEUE OVERFLOW') else end; procedure remove; begin end; begin initialise; repeat clrscr; writeln('Queues :-)!!!!!'); writeln('1. View Queue'); writeln('2. Add data to queue'); writeln('3. Remove data from Queue'); writeln('4. Exit'); readln(choice); if choice = 1 then view; if choice = 2 then add; if choice = 3 then remove; until choice = 4; end. Stephen Wed, 18 Jun 1902 08:00:00 GMT Ing. Franz Glase#2 / 3 Queues in Pascal without pointers If it is a queue literally, you don't need static pointers (indicex) at all. Better define a Type QeRec = Record filled : Boolean; txt : String; End; Var Queue = Array[0..10] of QeRec; Procedure Add(NewText : String); (* at the bottom of the serpent *) Var I : Integer; Begin if Queue[10].filled then Begin Errormessage.... no more space Exit; End; for I := 10 downto 1 do (* down is necessary not to overwrite all *) Queue[I] := Queue[I-1]; Queue[0].txt := NewText; Queue[0].filled := true; End; Procedure Remove; (* at the upper end of the serpent *) Var I : Integer; Begin if not Queue[0].filled then Begin Errormsg... nothing to remove Exit; (* important, else below would possibly crash *) End; I := 10; while not Queue[I].filled do I := I-1; (* or Dec(I); *) if I >= 0 then (* this IF is not really necessary*) Queue[I].filled := false; End; Procedure Initialize; Begin fillchar(Queue,sizeof(Queue),#0); End; Begin Initialize; .... End. NOTE: This is one possible solution, maybe not the best, but it reflects best the queue behaviour to have no static counters / pointers (here not meant as adress - pointers but index into the array). Kindest Regards, Franz Glaser, Austria please visit my URL -glaser computer_2(); Wed, 18 Jun 1902 08:00:00 GMT Frank Peel#3 / 3 Queues in Pascal without pointers Quote: >Hi all :-) >I am making a program about queues that will enable the user to add, view >and delete data from the queue with out the user of pointers. So far I >have coded the following code but I need some advice on what to do next. I >have already had some advice from some people but unfortunately they all >refered to pointers. My Computing A-level book also seems to give the >impression that the queues program is possible without pointers e.g. >^nodeptr. Anyway here is the code so far and thanks in advance:- > [source code snipped] Sorry this is late. Queues can be done in an array no problem. You need to work out the queue size and whether the queue is full from the relative positions of the front and rear indices. I assume rear is where an item joins the queue and front is the next element to be taken off. You initialise these to 0 so obviously you have decided that the queue is empty when front=rear and full when rear=front-1 allowing for wraparound. You can use modulo arithmetic to allow for wraparound, in other words the "full" condition is ((Rear+1) mod limit) = Front. You have to be careful to use +ve values with mod because for -ve values the mod operator in computer languages differs from what would normally expect with modulo arithmetic. Since x mod limit has a value [0..limit-1] it is convenient if the array goes 0..limit-1 as well. This would also fit better with front and read being initialised to 0. Since the pointer indices are defined this way (front=rear => empty), item [front] is the next item to be removed from the queue and item[rear] is where the next item _will_ go - it is not in use yet. Therefore the queue can have at most limit-1 elements. At that point rear will be front-1 but if you add the next element rear will catch up on front which is not allowed. The View method should start with item[Front] and loop until you reach item[rear] - you don't really want to go over the whole array if you want to display the queue. I don't think the condition for the queue being full is very obvious, and if you change your implementation it might change, so it might be a good idea to have a function isFull or something like that to put the condition in. That way if you get it wrong you fix it in just one place rather than everywhere you have "if q.size=limit" - which is wrong, should read "limit-1". Also size could be a function so you wouldn't have to maintain that variable all over the place. If queue was an object rather than a plain record you could make size a method and then you would use it the same way as you do now (e.g. writeln('the queue has ',q.size,' elements');) Also initialise, view, add and remove could be methods so you wouldn't have to put "q." in there. As a bonus you would then be able to have more than one queue (var q, w:queue) which you can't with "q." all over the place. Finally you have a lot of clrscrs in there which will clear e.g. messages like the QUEUE OVERFLOW one before you can see them if your machine is any way fast! FP Wed, 18 Jun 1902 08:00:00 GMT Page 1 of 1 [ 3 post ] Relevant Pages 1. Multiple queues w/pointers!
This will "queue" the given method with the given parameter for execution in the main event loop, when all other events have been processed. In the example above, the reference to the object you wanted to free has gone, since the then-parent has finished execution, and the object you wanted to free can be freed safely.
The following program shows the use of QueueAsyncCall. If you press on the CallButton, 'Click 1', 'Click 2' and 'Async 1' is added to the LogListBox. Note that Async call is only executed after the CallButtonClick event has finished.
In the Pascal programming language, the assignmentoperator is the two character sequence :=instead of a single = character as in Java.Write a program that reads in a source file line by line.Each sequence:= in a line is changed into = before the line is output. (Of course, much more than this is needed to fully translatePascal to Java.)Use redirection for file input and output:
Hints: use a Scanner and nextLine()for input.The outer while loop of the program uses hasNextLine() to decide if it should continue.Use indexOf() to look for :=.Use substring() and concat() (or +)to create the transformed line.
An if statement or a while statementin Java should usually not containthe character =,unless it is part of ==, =, or !=.Sometimes, however, a single = is correct.Write a program that reads in a Java source program line by line andoutputs only those lines that start with "if" or "while" (possibly preceded by whitespace) and thatsomewhere contain a single equal sign with at least one spaceon the left and right: " = " .The user can then inspect each line of the output for problems.A much better program would detect a single "=" even when not surrounded by spaces,but that is much harder to write.
The English, words "a" and "the" can mostly be removed from sentenceswithout affecting the meaning.This is an opportunity for compressing the size of text files!Write a program that inputs a text file, line-by-line, and writes outa new text file where each line has the useless words eliminated.
First write a simple version of the programthat replaces substrings " a " and " the " in each line with a single space.This will remove many words, but sometimes these words occur at thebeginnings or ends of lines, and sometimes the words start with capitals.So, improve your first program so that it handles those situations as well.
Write a program that decodes a secret message contained in a text file.The first line of the text file contains the key-phrase.Then the file contains a sequence of integers, each of which indexesthe key-phrase.Find the character corresponding to each integer and output the secret message.Note if a character character such as 'e' occurs several places in the key-phraseit may be encoded as different integers in different parts of the secret message.
Now, hold tight because you are going to be amazed by this fact. Each element in Pascal's Triangle can be calculated using the element's row and column number. For example, the value of the element in the third row and second columns will be equal to 2C1, which is 2. Note how the row and column numbers are subtracted by 1 while calculating the value. This is because counting in programming starts from 0 and not from 1. Look at the image below, to have a clearer understanding. 2b1af7f3a8