L215 Report

Only available on StudyMode
  • Topic: Abstract data type, Data structure, Source code
  • Pages : 16 (3708 words )
  • Download(s) : 80
  • Published : March 24, 2013
Open Document
Text Preview
Experiment L215

ICIS Practicum Laboratory

In any programming language, there are several data types that are available for programmers to use, such as integers, floating point numbers, strings or characters. Many applications need more complicated structures of data that can be added on a program-to-program basis; hence, the notion of data abstraction.

An abstract data types (ADT) consists of data together with functions that operate on the data. We also can say that it’s a set of data values and associated operations that are precisely specified independent of any particular implementation. An abstract data types is “abstract” in the sense that how data are represented and how functions are implemented are not specified. Only the behavior of the functions is specified. Examples of ADTs include that of Stack, Queue and Links.

In this lab, we are going to implement some of familiar ADTs like stack and queue using Visual C++ programming language. In this experiment we were more focus on the data structures in stead of programming language skills.

The objectives of the experiment are: a) Understand on the design and implementation of abstract data types. b) Able to implement ADTs using appropriate data structures. c) Able to process and manipulate data elements associated with ADTs.

3.0 THEORETICAL BACKGROUND 3.1 The stack abstract data type
The stack is ubiquitous. It is a temporary abstract data type and data structure based on the principle of Last in First out (LIFO).A stack is a list of items with the restriction that insertion and deletion can only be performed in only one position, namely the end of the list called the “top”. The fundamental operations of the stack are “push”, which is equivalent to insert, add -1-

Experiment L215

ICIS Practicum Laboratory

the item at the top of the stack and “pop” operation which removes the most recently added item. Shown as Figure 2.1 Stacks are sometimes known as LIFO (last in, first out) list and a model depicting this ADT is shown in Figure 2.2 below.

Figure 2.1 Basic operation of a stack

Figure 2.2 Model of a Stack

3.2 The queue abstract data type
In providing services in computer science, transport, and operations research a queue are a buffer where various entities such as data, objects, persons, or events are stored and waiting to be processed. The most well known operation of the queue is the First-In-First-Out (FIFO) queue process — In a FIFO queue, the first element in the queue will be the first one out; this


Experiment L215

ICIS Practicum Laboratory

is equivalent to the requirement that whenever an element is added, all elements that were added before have to be removed before the new element can be invoked. The Basic operations on a queue are enqueue, which inserts an element at the end of the list (call the rear), and dequeue, which deletes (and returns) the element at the start of the list (also known as front). Figure 2.3 shows a model of a queue. Queue is sometimes known as FIFO (First in, first out) list.

Figure 2.3 Model of a queue

4.0 PROCEDURE OF ADTS IMPLEMENTATION (LAB ASSESSMENT) 4.1 Implementation of a stack A stack may be implemented using an array. We use a variable t to index the top of the stack. When an item is pushed onto the stack, we increment t and put the item in the cell at index t. When an item is popped off the stack, we decrement t as well.

To construct a program to implement the stack ADTs generally includes three steps which are variables and functions declarations, generate sub-functions for basic operation and construct over all program to express the stack data type.


Experiment L215

ICIS Practicum Laboratory

a) b) c) d) e) f) g)

empty stack push “88” push “264” and “1” pop pop push “13” pop until empty

Figure 4.1 Sample of stack implementation

a) Variables and function declarations Previously we were using Pseudocode...
tracking img