Abstract Data Type (ADT)
Abstract Data Type (ADT)
Abstract Data Type (ADT)
Features of ADT:
Abstraction: The user does not need to know the implementation of the data structure only
essentials are provided.
Better Conceptualization: ADT gives us a better conceptualization of the real world.
Robust: The program is robust and has the ability to catch errors .
LIST ADT –
Node contains two field data which is actual data value and next field is address of next node
Stack ADT –
In Stack ADT Implementation instead of data being stored in each node, the pointer to data is
stored.
stack head also contains a pointer to top and count of number of entries currently in stack.
Queue ADT –
Queue ADT follows the basic design of the stack abstract data type.
Each node contains data and the link pointer to the next element in the queue then responsibility is to
allocate memory for storing the data.
Functions of Queue ADT –
i) isEmpty() – Return true if the queue is empty, otherwise return false.
ii) isFull() – Return true if the queue is full, otherwise return false.
iii) enqueue() – Insert an element at the end of the queue.
iv) dequeue() – Remove and return the first element of the queue, if the queue is not empty.
2. Array –
Array is collection of elements of same data types
Declaration of array –
Example –
int arr[11];
Basic operations –
#include <stdio.h>
void main() {
int i;
#include <stdio.h>
void main()
int i, x, pos, n = 5;
printf("Array elements before insertion\n");
pos = 4;
n++;
printf("\n");
getch();
#include <stdio.h>
void main()
int k = 2, n = 5;
int i, j;
j = k;
while( j < n) {
arr[j-1] = arr[j];
j = j + 1;
n = n -1;
{
printf("arr[%d] = %d, ", i, arr[i]);
}
}
#include <stdio.h>
void main()
{
printf("arr[%d] = %d, ", i, arr[i]);
break;
}
j = j + 1;
}
printf("\Element %d is found at %d position", ele, j+1);
}
v) Update Operation -
#include <stdio.h>
void main()
}
arr[pos-1] = ele;
{
printf("arr[%d] = %d, ", i, arr[i]);
Types of Array –
Multi-Dimensional Arrays -
In multi-dimensional arrays, we have two categories:
Two-Dimensional Arrays
Three-Dimensional Arrays
1. Two-Dimensional Arrays –
2. Three-Dimensional Arrays –
When we require to create two or more tables of the elements to declare the array elements, then in such a
situation we use three-dimensional arrays.
Syntax: DataType ArrayName[size1][size2][size3];
For Example: int a[5][5][5];
3. Array as ADT –
The array is a basic ADT that holds an ordered collection of items accessible by an integer index
Arrays are defined as ADT’s because they are capable of holding contiguous elements in the
same order. And they permit access for the specific element via index or position.
Example –
They are abstract because they can be int , String
int[] arr = new int[1];
1 2 3 4 5 6 7 9
Array Index