Guide for steel designers to design a self standing stackFull description
Descripción: document
steel stackFull description
ba
Descripción: ESTRUCTURA DE DATOS
script mikrotikFull description
Message Queues, Mailboxes, And Pipes - RTOSFull description
MAKALAH TAKHRIJ HADITS.docDeskripsi lengkap
Full description
Deskripsi lengkap
Full description
EHP7 for SAP ERP 6.0 SP Stacks - Release & Information Note
MB3B
Full description
Data Structures: Abstract Data Type (ADT)
Stacks & Queues
Abstract Data Types Types
All processin processing g on a comput computer er involv involves es the manipula manipulatio tion n of data data This This data data can be organi!ed in the computer"s memory in different #ays according to ho# it is to be processed$ and the different methods of organi!ing data are kno#n as data structures %omputer languages such as ascal have built'in elementary data types (such as integer$ real$ oolean and char) and some built'in type structured or composite data types (data structures) such as record$ array and string These composite data types are made up of a number of elements of a specified type such as integer or real
Some data structures such as ueues$ stacks and binary trees are not built into the language and have to be constructed by the programmer These are kno#n as Abstract Data Types (ADT) An Abstract Data Type (ADT) is the combination of a data structure and a group of functions or procedures designed to manipulate the data #ithin the data structure
An ADT must possess the follo#ing characteristics:
the facility to create a container to hold h old the data*
the facility to add a ne# element to the container*
the facility to remove+delete an element #hich satisfies some criterion from the container*
the facility to find an element #hich satisfies some criterion criterion #ithin the container*
the facility to destroy the container #hen it is no longer reuired
Stacks
A stack is a particular particular kind of seuence seuence that may only be accessed at one end$ kno#n as the top of the stack (like plates on a pile in a cafeteria) ,nly t#o operations can be carried out on a stack Adding a ne# item involves placing it on the top of the stack (pushing or stacking the item) -emoving an item involves the removal of the item that #as most recently added (popping the stack) The stack is a LIFO Structure . Last In$ First Out
repared by / /ones
age 0 of 1
Data Structures: Abstract Data Type (ADT)
Stacks & Queues
2ote that items do not move up and do#n as the stack is pushed and popped* instead$ the position of the top of the stack changes A pointer called a stack pointer indicates the position of the top of the stack
Characteristics of a Stack
The specific operation #hich defines a stack is the concept of 34ast'in'first'out5
Data elements #hich have been added to the container are removed from the container in the reversed order to #hich they are inserted
Typically$ this ADT is identified by a variable called 3the head5 #hich identifies the location of the most recent element added to the container
The functions of 3push5 and 3pop5 are typically used to describe the process of inserting and deleting elements respectively$ from the stack
Implementation of a stack
A stack can be represented in memory by an array and t#o additional integer variables$ one holding the si!e of the array (ie the ma6imum si!e of the stack) and one holding the pointer to the top of the stack (Top) Top #ill initially be set to 7$ representing an empty stack
8 ; < = > 0
9a6StackSi!e 8
Anne 9illie %harles
Top =
Diagram showing an array that can hold a maimum of ! elements with " items currently in the stock#
repared by / /ones
age > of 1
Data Structures: Abstract Data Type (ADT)
Stacks & Queues
The following pseudocode may be used to add $%push&' an element onto a stack(
rocedure ush ?f Top 9a6StackSi!e Then @rite 3Stack is full5 lse Add 0 to Top StackBTopC 2e#?tem nd?f ndrocedure
The following pseudocode may be used to remo)e $%pop&' an element from a stack(
rocedure op ?f Top 7 Then @rite 3Stack is empty5 lse opped?tem StackBTopC Subtract 0 from Top nd?f ndrocedure
Applications of stacks
Stacks are very important data structures in computing They are used in many different situations in computing$ for e6ample: •
to store return addresses$ parameters and register contents #hen subroutines are called @hen the subroutine ends$ the address at the top of the stack is popped and the computers continues e6ecution from that address*
•
translating from one computer language to another$ and transferring control from one part of a program to another*
•
in evaluating mathematical e6pressions held in reverse olish notation$ ie a form of notation used by compilers as an intermediate step in translating e6pressions such as A: (%) E D+
Stacks can also be used to reverse the elements of a ueue This is done by pushing the elements of the ueue one by one on to a stack$ and then popping them one by one and replacing them in the ueue
repared by / /ones
age = of 1
Data Structures: Abstract Data Type (ADT)
Stacks & Queues
*ueue
A ueue is a First ?n First ,ut (F?F,) data structure 2e# elements may only be added to the end of a ueue$ and elements may only be retrieved from the front of a ueue The seuence of data items in a ueue is determined$ therefore$ by the order in #hich they are inserted The si!e of the ueue depends on the number of items in it$ Gust like a ueue at the cinema or supermarket checkout
Implementation of a +ueue
A ueue can be implemented as an array #ith a pointer to the front of the ueue and a pointer to the rear of the ueue An integer holding the si!e of the array (the ma6imum si!e of the ueue) is needed$ and it is useful to have an e6tra variable giving the number of items currently in the ueue
/ohn
%atherine
-ob
Front 0
-ear =
9a6Si!e 8
2umber?nQueue =
After > people have left the ueue and = more have Goined$ the ueue #ill look like this: -ob Front = 9a6Si!e 8
9a6
4isa
Anna -ear 8
2umber?nQueue <
2o# #hatH ,nly < people are in the ueue but the end of the array has been reached To overcome this problem$ the elements could be shuffled along$ so the front of the ueue is al#ays in location 0 This is kno#n as Linear *ueue Io#ever$ busy ueues #ould spend rather a lot of time shuffling elements Another method to overcome the problem is to implement the ueue as a Circular *ueue $ so that #hen the ne6t person Goins they enter at the front of the array:
en
repared by / /ones
-ob
9a6
4isa
Anna
age < of 1
Data Structures: Abstract Data Type (ADT) -ear 0
Stacks & Queues
Front =
9a6Si!e 8
2umber?nQueue ;
,rocedures to implement a circular +ueue
The abo)e +ueue may be implemented by declaring )ariables as follows(
QB8C as String Front$ -ear$ 2umber?nQueue as ?nteger
To initiali-e the +ueue(
rocedure ?nitiali!e Front 0 -ear 8
Jor -ear 7K
2umber?nQueue 7 ndrocedure
To add an element to the +ueue(
rocedure nQueue ?f 2umber?nQueue 8 Then @rite 3Queue overflo#5 lse ?f -ear 8 Then -ear 0 lse
or -ear (-ear 9od 8) E 0 Add 0 to -ear
nd?f QB-earC 2e#?tem Add 0 to 2umber?nQueue nd?f ndrocedure To remo)e an element from the +ueue(
repared by / /ones
age ; of 1
Data Structures: Abstract Data Type (ADT)
Stacks & Queues
rocedure DeQueue ?f 2umber?nQueue 7 Then @rite 3Queue empty5 lse 2e#?tem QBFrontC Subtract 0 from 2umber?nQueue ?f Front 8 Then Front 0 lse
or Front (Front 9od 8) E 0 Add 0 to Front
nd?f nd?f ndrocedure
Implementing a +ueue as a linked list
A ueue may be implemented as a special kind of linked list$ #ith each element in the ueue pointing to the ne6t item An e6ternal pointer points to the front of the ueue$ and items may only be removed from the front of the list and added to the end of the list
Data
Data
Data
Data
Front The front of the ueue is accessed through the pointer front To add an element to the ueue$ the pointers have to be follo#ed until the node containing a pointer of 7 is reached signifying the end of the ueue$ and this pointer is then changed to point to the ne# node (?n some implementations t#o pointers are kept* one to the front and one to the rear This saves having to traverse the #hole ueue #hen a ne# element is to be added)
repared by / /ones
age 8 of 1
7
Data Structures: Abstract Data Type (ADT)
Stacks & Queues
Applications of a +ueue
,utput #aiting to be printed is commonly stored in a ueue on disk ?n a room full of net#orked computers$ several people may send #ork to be printed at more or less the same time y putting the output into a ueue on disk$ the output is printed on a first come$ first served basis as soon as the printer is free
%haracters typed at keyboard are held in a ueue in a keyboard buffer
/obs #aiting to be run by the computer may be held in a ueue
Characteristics of a *ueue
The specific operation #hich defines a ueue is a concept of 3First'in'first'out5
Data elements #hich have been added to the container are removed from the container in e6actly the same order in #hich they #ere inserted
Typically$ this ADT is identified by a variable called 3the head5 #hich identifies the location of the longest e6isting element in the container and another variable called 3tail5 #hich identifies the most recent element added to the container
The functions of 3enueue5 and 3deueue5 are typically used to describe the process of inserting and deleting elements respectively from the ueue
?n the ueue$ data elements are inserted through the tail and removed from the head