Jump to content

Pseudo + Pointer diagram, Help from the masters

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
borny86

borny86

    Newbie

  • Members
  • Pip
  • 7 posts
Hi im struggeling with some excersises im intending to do.

First question ive done a Pointer diagram based on this code.

  NEW(NodePtr);				
  NodePtr^.Data := Rec;
  NodePtr^.Next := DB.Head;
  DB.Head := NodePtr;
  DB.Size := DB.Size + 1;

"Draw a pointer diagram, with explanatory text, showing how Add_Record in Book_DB works in the case where there are no records in the database. "



Second question, regarding psudo code?

I've attempted to write psudo code for the following piece of code.
FUNCTION Q_Present(Key : INTEGER; DB : TBookDB; VAR BookRec : TBookRec) : BOOLEAN;
VAR
  Pos : INTEGER;
BEGIN
  RESULT := FALSE;
  Pos := 1;
  WHILE (NOT RESULT) AND (Pos <= DB.Size) DO
  BEGIN
    IF DB.Recs[Pos].Key = Key THEN
    BEGIN
      RESULT := TRUE;
      BookRec := DB.Recs[Pos];
    END
    ELSE
    BEGIN
      Pos := Pos + 1;
    END
  END
END {Q_Present};

{ REQUIRES  TRUE}
{ RESULTS   RETURNS number of records in DB }

My psudo code

Set result to false.
Set position to 1.
When Result = False and Position less or equal to number of records
Start
Set Result to True
Record = Poistion of record.
Else
Increment Position by 1.


Im new to this forum, an I would be so grateful if anyone of you could help me.

btw this is not assessed its just a excesrise and really want to get a grip of it :irritated:.


Regards

Borny :irritated:

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Your pseudocode is missing the If condition.
Also, please add code tags to your code for easier reading.
Your image doesn't look correct. It seems like your diagrams don't correspond to the result of the statement to their left, but to the statement above.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
borny86

borny86

    Newbie

  • Members
  • Pip
  • 7 posts
Thanks f