1 / 11

Pascal Programming

Pascal Programming. Pointers and Dynamic Variables. Pascal Programming. The pointer . . . . . . addresses a location in a list. The pointer points to a node. Dynamic variables . . . . . . have an associated type. . . . almost any type maybe used but a file type. . Pascal Programming .

varsha
Télécharger la présentation

Pascal Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Pascal Programming Pointers and Dynamic Variables

  2. Pascal Programming • The pointer . . . • . . . addresses a location in a list. • The pointer points to a node. • Dynamic variables . . . • . . . have an associated type. • . . . almost any type maybe used but a file type.

  3. Pascal Programming • An assignment operator or read statement can establish the value of a dynamic variable. • A dynamic variable can be accessed by a write statement, by being an actual parameter or any other usual means.

  4. Pascal Programming • Dynamic variables differ from ordinary variables in two ways. . . • 1. Dynamic variables may be created and destroyed by the program. • 2. Dynamic variables have no names in Pascal. • To refer to a dynamic variable Pascal uses a pointer variable.

  5. Pascal Programming • Pointer variables . . . • . . . are declared • . . . have a type. • . . . have an associated identifier. • . . . point to a dynamic variable. • Syntax • var • Pointer: ^(type); continues . . .

  6. Pascal Programming • The type associated with the pointer is the domain type. • The pointer can only point to that type . . . another type requires an additional pointer or a redirection of the pointer. • The predefined procedure new can be used to point to a new dynamic variable.

  7. Pascal Programming • Pascal has a working phrase—the thing pointed to by Pointer . . . • . . .this translates into pointer ^. • Pointer=P • The value of P points to a dynamic variable—not P points to . . . • The assignment operator can redirect the pointer – P:=P1 • After redirection, you need to check to see that P1^ points to the appropriate type.

  8. Pascal Programming • Remember Nodes and Pointers need to be declared. • Pascal wants pointer type definition to precede node type definition. • nil, is a constant like the Boolean true or false. • It can be used as an end marker. • P^.LastNode:=nil

  9. Pascal Programming • Linked lists . . . • . . . consist of nodes with one pointer field. • . . . the pointers order the nodes into a list. • . . . the first node is called the head. • . . . the pointer would be called head because it points to the head of the linked list. • . . . nodes can be added at the head, the end or at a predetermined location.

  10. Pascal Programming • Binary trees . . . • . . .have two pointers. • . . .programs can address every node of a tree by traversing it. • . . . Branching from the first node leads us to a right subtree and a left subtree. • Traversing can be accomplished by addressing the left then the right subtree, returning to the root node in the middle.

  11. Pascal Programming • Linked lists may be used for many of the same uses as arrays. • However, a program can alter the size of a linked list (not an array). . . • . . .nodes can be inserted and deleted. • These differences give linked lists new utility. • An empty list can be created by . . . • Head := nil

More Related