Data Structures Unit 1-Linear Structures
Data Structures Unit 1-Linear Structures
DATA STRUCTURES
Unit 1-Linear structures
Year/Sem : II/III
Subject Code: 1151CS102
Topic : Abstract Data Type
Faculty Name : Vijitha.S
Date : 07.08.2020
School of Computing
Vel Tech Rangarajan Dr. Sagunthala R&D Institute of
Science and Technology
Contents
Abstract Data Type - Definition
Types of ADT
List - Definition
List ADT - Definition
Operations of List ADT
Implementation of list ADT
Array ADT
Array implementation of a list
How to store a list in an array
and Project
Array ADT-operations
Management
(SEPM)
Advantages
8/07/2020 Department of Computer Science and Engineering
Abstract Data Type - Definition
Definition:
and Project
Management
(SEPM)
Types of ADT:
2.Stack ADT
3.Queue ADT.
and Project
Management
(SEPM)
and Project
Management
(SEPM)
Creating a list
Traversing the list
Inserting an item in the list
Deleting an item from the list
Concatenating two lists into one
and Project
Management
(SEPM)
and Project
Management
(SEPM)
and Project
Management
(SEPM)
and Project
Management
(SEPM)
and Project
Management
(SEPM)
and Project
Management
(SEPM)
1.Array ADT
and Project
Management
(SEPM)
and Project
Management
(SEPM)
Insertion
Deletion
Search
int main()
{
int A[] = {1,3,5,7};
int item = 8, k = 3, n = 5;
int i = 0, j = n;
printf("The original array elements are :\n");
for(i = 0; i<n; i++)
{
printf("A[%d] = %d \n", i, A[i]);
and Project
Management
} (SEPM)
n = n + 1;
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT-INSERTION
while( j >= k)
{
A[j+1] = A[j];
j = j - 1;
}
A[k] = item;
printf("The array elements after insertion :\n");
for(i = 0; i<n; i++)
{
printf("A[%d] = %d \n", i, A[i]);
and Project
} Management
(SEPM)
}
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT-INSERTION
Before Insertion:
1 3 5 7
After Insertion:
1 3 5 7 8
and Project
Management
(SEPM)
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT-DELETION
Pseudocode:
delete()
declare array A
read n
for (i=0;i<n;i++)
read A[i]
get position k
j=k
while( j < n)
A[j-1] = A[j]
and Project
j = j + 1 Management
(SEPM)
n=n-1
print array A
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT-DELETION
Sample code:
int main()
{
int A[] = {1,3,5,7,8};
int k = 3, n = 5;
int i, j;
printf("The original array elements are :\n");
for(i = 0; i<n; i++)
{
printf("A[%d] = %d \n", i, A[i]);
and Project
Management
} (SEPM)
j = k;
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT-DELETION
while( j < n)
{
A[j-1] = A[j];
j = j + 1;
}
n = n -1;
printf("The array elements after deletion :\n");
for(i = 0; i<n; i++)
{
printf("A[%d] = %d \n", i, A[i]);
and Project
Management
} (SEPM)
}
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT-DELETION
Before Deletion
1 3 5 7 8
After Deletion:
1 3 7 8
and Project
Management
(SEPM)
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT- SEARCH
Pseudocode:
search()
declare array A
read n
for (i=0;i<n;i++)
read A[i]
read k(element to be searched)
set f=0
for(i=0;i<n;i++)
if(A[i]==k)
f=1
print i and Project
break Management
(SEPM)
if(f==0)
print “Element not found”
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT- SEARCH
Sample code:
int main()
{
int list[20],size,i,sElement;
printf("Enter size of the list: ");
scanf("%d",&size);
printf("Enter any %d integer values: ",size);
for(i = 0; i < size; i++)
and Project
Management
(SEPM)
scanf("%d",&list[i]);
printf("Enter the element
8/07/2020
to be Search: ");
Department of Computer Science and Engineering
ARRAY ADT- SEARCH
scanf("%d",&sElement);
for(i = 0; i < size; i++)
{
if(sElement == list[i])
{
printf("Element is found at %d index", i);
break;
}
}
and Project
if(i == size) Management
(SEPM)
printf("Given element is not found in the list!!!");
}
8/07/2020 Department of Computer Science and Engineering
ARRAY ADT- SEARCH
and Project
Management
(SEPM)
and Project
Management
(SEPM)