100 likes | 395 Views
Data Structures. You have already come across elementary data types integer real Boolean And some structured data types (data structures) string array record. Data Structures. Other data structures such as Queues Stacks & Binary Trees Have to be constructed by the programmer.
E N D
Data Structures You have already come across elementary data types • integer • real • Boolean And some structured data types (data structures) • string • array • record
Data Structures Other data structures such as Queues Stacks & Binary Trees Have to be constructed by the programmer
Queues Queues are data structures that maintain the order of FIFO First In First Out
Queues New elements may only be added to the end of a queue; and elements may only be retrieved from the front of a queue. Pointers mark the front and rear of the queue. front rear
Stacks The terminology associated with stacks comes from the spring-loaded plate containers you get in canteens. They maintain the order LIFO Last In First Out
Stacks New elements are added to the top of the stack. The item at the top of the stack is the first to be removed. top
Queues and Stacks Queues are used for • Characters typed at a keyboard are held in a keyboard buffer • Output waiting to be printed is commonly stored in a queue Stacks are used for • Calculations • Used to store the return address when a subroutine is called
Queues and Stacks An example http://www.cmpe.boun.edu.tr/~akin/cmpe223/stack_queue/chap2_2.htm
Queues and Stacks Queues are more difficult to implement than Stacks. A Stack can be used to reverse a Queue. Stacks and Queues have preset sizes. If you try to add an element to a queue or stack that has no free space you get overflow. If you try to remove an element from an empty queue or stack you get underflow.