Sei sulla pagina 1di 11

SUMMARY OF LINEAR DATA

STRUCTURES
Abstract Data Types

• Abstract Data type (ADT) is a type (or class) for objects whose
behaviour is defined by a set of value and a set of operations.
• The definition of ADT only mentions what operations are to be
performed but not how these operations will be implemented.
• It does not specify how data will be organized in memory and what
algorithms will be used for implementing the operations.
• It is called “abstract” because it gives an implementation-
independent view. The process of providing only the essentials and
hiding the details is known as abstraction.
STACK ABSTRACT DATA TYPE
The stack is defined by the following structure and operations. The stack operations
are given below.
1. Stack() – creates a new empty stack. It does not need parameters and returns an
empty stack.
2. push(item) – adds a new item on the top of the stack. It adds the item and
returns nothing.
3. pop() – removes the most recent added item from the top of stack. It doesn’t
need parameters and returns the item. It modifies stack by removing an item from
the top of stack.
4. peek() – returns the most recent added item (Top) from the stack but does not
remove it.
5. isEmpty() – test to see whether the stack is empty.
6. size() – returns the number of items on the stack.
STACK ADT
class Stack:
def __init__(self):
self.items = []

def isEmpty(self):
return self.items == []

def push(self, item):


self.items.append(item)

def pop(self):
return self.items.pop()

def peek(self):
return self.items[len(self.items)-1]

def size(self):
return len(self.items)
QUEUE ABSTRACT DATA TYPE
1. Queue() – creates a new queue that is empty. It does not need parameters
and returns an empty queue.
2. enqueue(item) – adds a new item on the rear of the queue. It adds the
item and returns nothing.
3. dequeue() – removes the item at the front from the queue. It doesn’t
need parameters and returns boolean value. It modifies the queue.
4. isEmpty() – test to see whether the queue is empty. It doesn’t need
parameters and returns a boolean value.
5. size() – returns the number of items on the queue. It doesn’t need
parameters and returns an integer.
class Queue:
QUEUE def __init__(self):
self.items = []

def isEmpty(self):
return self.items == []

def enqueue(self, item):


self.items.insert(0,item)

def dequeue(self):
return self.items.pop()

def size(self):
return len(self.items)
DEQUEUE ABSTRACT DATA TYPE
Definition: A dequeue is structured, as described above, as an ordered collection of items
where items are added and removed from either end, either front or rear. The dequeue
operations are given below.
1. Dequeue() – creates a new empty dequeue. It does not need parameters and returns an
empty dequeue.
2. addFront(item) – adds a new item on the front of the dequeue. It adds the item and
returns nothing.
3. addRear(item) – adds a new item on the rear of the dequeue. It adds the item and returns
nothing.
4. removeFront() –removes the front item from the dequeue. It needs no parameters and
returns the item. The dequeue is modified.
5. removeRear() – removes the rear item from the deque. It needs no parameters and
returns the item. The dequeue is modified
6. isEmpty() – test to see whether the dequeue is empty. It doesn’t need parameters and returns a boolean value.
7. size() – returns the number of items on the dequeue. It doesn’t need parameters and returns an integer.
DEQUEUE
• OPERATION CONTENT VALUE
class Dequeue:
DEQUEUE def __init__(self):
self.items = []

def isEmpty(self):
return self.items == []

def addFront(self, item):


self.items.append(item)

def addRear(self, item):


self.items.insert(0,item)

def removeFront(self):
return self.items.pop()

def removeRear(self):
return self.items.pop(0)

def size(self):
return len(self.items)

Potrebbero piacerti anche