Download Records, Stacks and Queues

yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts

Programming language wikipedia, lookup

Flow-based programming wikipedia, lookup

Stream processing wikipedia, lookup

C Sharp syntax wikipedia, lookup

Functional programming wikipedia, lookup

Falcon (programming language) wikipedia, lookup

Object-oriented programming wikipedia, lookup

Buffer overflow protection wikipedia, lookup

Abstraction (computer science) wikipedia, lookup

C syntax wikipedia, lookup

C Sharp (programming language) wikipedia, lookup

Go (programming language) wikipedia, lookup

Reactive programming wikipedia, lookup

Turbo Pascal wikipedia, lookup

Structured programming wikipedia, lookup

Smart Pascal wikipedia, lookup

Pascal (programming language) wikipedia, lookup

Corecursion wikipedia, lookup

Records, Stacks & Queues
Pascal Programming
Record data types—a complex type that
combines different data types into a
single record.
 Sometimes called set types.
 The individual elements of a record are
called fields or components or
component fields.
Pascal Programming
Each field has a name . . .the field identifier.
 The field identifiers provide a means of
accessing each field in the record, similar to
an array index.
 Each field has a type, which is established
when the record is declared.
 The value of a record is a collection of values.
There is a value in each field.
Pascal Programming
The component of a record variable is a
component variable.
 . field identifier . . .specifies a
component variable.
– e g: Business1.PresidentsLastName
 Though a record is a collection of
values, it can sometimes be treated as
a single value.
Pascal Programming
So . . .
– The record variable describes the raw
– Record value indicates all the values in
the record.
– Component values indicate the field
– Field identifiers name the fields in record.
Pascal Programming
Syntax . . .
 type
– Business =
• record
BusinessName: string[30];
StreetAddress: string[35]
City: string[20];
State: string[2];
zip: integer;
• end;
Pascal Programming
A programmer may want to structure
data with a hierarchy of records.
 e g:
– student identification
– birth date and age
– core courses . . .etc . . .
Pascal Programming
Records for a group may be read into
an array.
 Thus, we see that . . .
– data structures are a means of
organizing, storing and manipulating data.
How do we chose which structure to
– Everything being equal, chose the one that can be
understood and worked with most easily.
Pascal Programming
 If
all items are of the same type
. . .a single array of that type works
 If items differ in type, use an array
of records.
 Or, use parallel arrays.
Pascal Programming
with statements . . .
 With provides instruction(s) to carry out
an operation.
 Syntax
– with record_variable_list do
• statement (usually compound)
The records_variable_list is separated
by commas.
Pascal Programming
Stacks and Queues
 The stack, a specialized data structure,
compares to a stack of shoe boxes.
 New data goes into a box on the top of
the stack.
 To read from the stack, access the first
box, discard it, read the second box,
discard it etc . . ..
Pascal Programming
Stacks serves the purpose of reversing
the order of data -- first in, last out.
 e g: stacktop = (TopValue) -1 . . . This
creates a decrementation of the stack.
The text illustrated using the stack to match
parenthesis. Find and save a left parenthesis
then look for the right one, eliminate all
characters in between. Cry fowl when a left
parenthesis occurs again without a right one.
Pascal Programming
Queue . . . A data structure for first
in/first out data handling. The opposite
of the stack.
 Like a waiting line . . .first come . . .first
 A queue can be implemented so that as
the array empties and reaches the end
the beginning fills again. It becomes
Pascal Programming
Pascal Sets
 Sets contain data like a list but that data
is unordered.
 To use sets in a variable, we use set
 The ordinals in the sets are its
 These are the Base_type of the set.
Pascal Programming
 type
– Grade = set of 0 .. 100;
– superior: grade = [94 .. 100]
The first illustrates the declaration of a
set and the second the appending of a
typed constant.