SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
ADT OF LISTS
DATA STRUCTURE
NADAR SARASWATHI COLLEGE OF ARTS AND
SCIENCE,THENI.
B.NIVEGEETHA(I-MSC(CS))
ADT(ABSTRACT DATA TYPES)
Abstract Data type (ADT) is a type (or class)
for objects whose behavior is defined by a set of
value and a set of operations. We can think
of ADT as a black box which hides the
inner structure and design of the data type.
LIST ADT
We all have an intuitive understanding of what we
mean by a "list". We want to turn this intuitive
understanding into a concrete data structure with
implementations for its operations. The most
important concept related to lists is that of position.
In other words, we perceive that there is a first
element in the list, a second element, and so on.
So, define a list to be a finite, ordered sequence of
data items known as elements. This is close to the
mathematical concept of a sequence.
GENERAL PROGRAM
public interface List {
// List class ADT
// Remove all contents from the list, so it is once again
empty
public void clear();
// Insert "it" at the current location
// The client must ensure that the list's capacity is not
exceeded
public boolean insert(Object it);
// Append "it" at the end of the list
// The client must ensure that the list's capacity is not
Exceeded
public boolean append(Object it);
// Remove and return the current element
public Object remove();
// Set the current position to the start of the list public
void moveToStart();
// Set the current position to the end of the list
public void moveToEnd();
// Move the current position one step left, no change
if already at beginning
public void prev();
// Move the current position one step right, no
change if already at end
public void next();
// Return the number of elements in the list public int
length();
// Return the position of the current element public int
currPos();
}
LINKED LIST
 A linked list is a linear data structure, in which the
elements are not stored at contiguous memory
locations. The elements in a linked list are linked
using pointers as shown in the below image:
 In simple words, a linked list consists of nodes
where each node contains a data field and a
reference(link) to the next node in the list.
WHY LINKED LISTS?
Arrays can be used to store linear data of similar
types, but arrays have following limitations.
1) The size of the arrays is fixed: So we must know
the upper limit on the number of elements in
advance. Also, generally, the allocated memory is
equal to the upper limit irrespective of them.
2) Inserting a new element in an array of elements is
expensive, because room has to be created for the
new elements and to create room existing elements
have to shifted.
INSERTING AN ELEMENT IN
LINKED LISTS
 The new node is always added before the head of the given
Linked List. And newly added node becomes the new head of
the Linked List. For example if the given Linked List is 10->15-
>20->25 and we add an item 5 at the front, then the Linked
List becomes 5->10->15->20->25. Let us call the function that
adds at the front of the list is push(). The push() must receive
a pointer to the head pointer, because push must change the
head pointer to point to the new node.
INSERTION PROGRAM
void push(struct Node** head ref, int new data)
{
/* 1. allocate node */
struct Node* new node = (struct Node*) malloc(sizeof(struct Node));
/* 2. put in the data */
new node->data = new data;
/* 3. Make next of new node as head */
new node->next = (*head ref);
/* 4. move the head to point to the new node */
(*head ref) = new node;
}
DELETING AN ELEMENT IN
LINKED LISTS
 To delete a node from linked list, we need to do
following steps.
1) Find previous node of the node to be deleted.
2) Changed next of previous node.
3) Free memory for the node to be deleted.
DELETION PROGRAM
void ListDelete(nodeT **listP, elementT value)
{
nodeT *currP, *prevP;
/* For 1st node, indicate there is no previous.*/
prevP = NULL;
/* * Visit each node, maintaining a pointer to * the previous node we
just visited. */
for (currP = *listP; currP != NULL; prevP = currP, currP = currP>next)
{ if (currP->element == value) {
/* Found it. */
if (prevP == NULL)
{ /* Fix beginning pointer. */
listP = currP->next; }
DELETION
Else
{
/* * Fix previous node's next to * skip over the removed
node. */
prevP->next = currP->next;
}
/* Deallocate the node. */
free(currP);
/* Done searching. */
return;
}
}
}
ARRAY BASED
IMPLEMENTATION
 #include<stdio.h>
#include<conio.h>
#define MAX 10
void create();
void insert();
void deletion();
void search();
void display();
int a,b[20], n, p, e, f, i, pos;
void main()
{
//clrscr();
int ch;
char g='y';
do
{
printf("n main Menu");
printf("n 1.Create n 2.Delete n 3.Search n 4.Insert n 5.Displayn 6.Exit n");
printf("n Enter your Choice");
scanf("%d", &ch);
void create()
{
printf("n Enter the number of nodes");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("n Enter the Element:",i+1);
scanf("%d", &b[i]);
}
}
void deletion()
{
printf("n Enter the position u want to delete::");
scanf("%d", &pos);
if(pos>=n)
{
printf("n Invalid Location::");
}
else
{
for(i=pos+1;i<n;i++)
{
b[i-1]=b[i];
}
n--;
}
printf("n The Elements after deletion");
for(i=0;i<n;i++)
{
printf("t%d", b[i]);
}
}
void search()
{
printf("n Enter the Element to be searched:");
scanf("%d", &e);
for(i=0;i<n;i++)
{
if(b[i]==e)
{
printf("Value is in the %d Position", i);
}
else
{
printf("Value %d is not in the list::", e);
continue;
}
}
}
void insert()
{
printf("n Enter the position u need to insert::");
scanf("%d", &pos);
if(pos>=n)
{
printf("n invalid Location::");
}
else
{
for(i=MAX-1;i>=pos-1;i--)
{
b[i+1]=b[i];
}
PROGRAM
printf("n Enter the element to insert::n");
scanf("%d",&p);
b[pos]=p;
n++;
}
printf("n The list after insertion::n");
display();
}
void display()
{
printf("n The Elements of The list ADT are:");
for(i=0;i<n;i++)
{
printf("nn%d", b[i]);
}
}
ARRAY IN LIST ADT
 In computer science, an array data structure, or
simply an array, is a data structure consisting of a
collection of elements (values or variables), each
identified by at least one array index or key. An
array is stored such that the position of each
element can be computed from its index tuple by a
mathematical formula.The simplest type of data
structure is a linear array, also called one-
dimensional array.
INSERTIND AND DELETING
AN ELEMENT IN ARRAY
APPLICATIONS OF LIST ADT
 Lists can be used to implement Stacks , Queues.
 Lists can also be used to implement Graphs. (Adjacency list
representation of Graph).
 Implementing Hash Tables :- Each Bucket of the hash table
can itself be a linked list. (Open chain hashing).
 Undo functionality in Photoshop or Word . list of states.
 A polynomial can be represented in an array or in a linked list
by simply storing the coefficient and exponent of each term.
 However, for any polynomial operation , such as addition or
multiplication of polynomials , linked list representation is
more easier to deal with.
 lists are useful for dynamic memory allocation.
 The real life application where the circular linked list is used is
our Personal Computers, where multiple applications are
running.
THE END

More Related Content

PDF
CSS selectors
PPTX
Introducing CSS Grid
PPT
Cascading Style Sheets (CSS) help
PPTX
Using Excel Functions
PPT
Javascript arrays
PPTX
Css pseudo-classes
PPTX
Html vs xhtml
PPTX
OOPS Basics With Example
CSS selectors
Introducing CSS Grid
Cascading Style Sheets (CSS) help
Using Excel Functions
Javascript arrays
Css pseudo-classes
Html vs xhtml
OOPS Basics With Example

What's hot (20)

PDF
Polymorphism
PPT
PPT
Collection Framework in java
PPTX
Cascading style sheet
PPTX
Introduction to CSS
PPTX
Basic data structures in python
PPTX
Java script array
PPT
Abstract data types
PPTX
Dynamic Polymorphism in C++
PPT
Abstract class in java
PPTX
single linked list
PPT
List Data Structure
PPT
XML and DTD
PDF
Set methods in python
PDF
Php array
PPT
Java Collections Framework
PPT
PPTX
Java Inheritance - sub class constructors - Method overriding
Polymorphism
Collection Framework in java
Cascading style sheet
Introduction to CSS
Basic data structures in python
Java script array
Abstract data types
Dynamic Polymorphism in C++
Abstract class in java
single linked list
List Data Structure
XML and DTD
Set methods in python
Php array
Java Collections Framework
Java Inheritance - sub class constructors - Method overriding
Ad

Similar to Adt of lists (20)

PPTX
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
PPTX
EC2311 – Data Structures and C Programming
PPTX
unit 1.pptx
PPTX
Data Structures and Algorithms: introduction
PPT
Lecture 3 List of Data Structures & Algorithms
PPT
lecture 02.2.ppt
PPTX
DS_LinkedList.pptx
PPT
Unit 1 linked list
PPTX
What is Link list? explained with animations
PPT
Algo>ADT list & linked list
PPT
Linked list introduction and different operation
PDF
Fjdkkdnncmckkgkhkhkkhkhkhkhkhkhkhkhkhkhhl
PPT
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
PPT
linked list (c#)
PPT
Lecture2
PPT
Data Structures 3
PPTX
Arrays and linked lists
PPTX
Data structures - unit 1
PPTX
ITS-105.pptxvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
PPT
dynamicList.ppt
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
EC2311 – Data Structures and C Programming
unit 1.pptx
Data Structures and Algorithms: introduction
Lecture 3 List of Data Structures & Algorithms
lecture 02.2.ppt
DS_LinkedList.pptx
Unit 1 linked list
What is Link list? explained with animations
Algo>ADT list & linked list
Linked list introduction and different operation
Fjdkkdnncmckkgkhkhkkhkhkhkhkhkhkhkhkhkhhl
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
linked list (c#)
Lecture2
Data Structures 3
Arrays and linked lists
Data structures - unit 1
ITS-105.pptxvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
dynamicList.ppt
Ad

Recently uploaded (20)

PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cardiovascular Pharmacology for pharmacy students.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
GDM (1) (1).pptx small presentation for students
Microbial diseases, their pathogenesis and prophylaxis
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPH.pptx obstetrics and gynecology in nursing
O7-L3 Supply Chain Operations - ICLT Program
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
2.FourierTransform-ShortQuestionswithAnswers.pdf
Open Quiz Monsoon Mind Game Prelims.pptx

Adt of lists

  • 1. ADT OF LISTS DATA STRUCTURE NADAR SARASWATHI COLLEGE OF ARTS AND SCIENCE,THENI. B.NIVEGEETHA(I-MSC(CS))
  • 2. ADT(ABSTRACT DATA TYPES) Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of value and a set of operations. We can think of ADT as a black box which hides the inner structure and design of the data type.
  • 3. LIST ADT We all have an intuitive understanding of what we mean by a "list". We want to turn this intuitive understanding into a concrete data structure with implementations for its operations. The most important concept related to lists is that of position. In other words, we perceive that there is a first element in the list, a second element, and so on. So, define a list to be a finite, ordered sequence of data items known as elements. This is close to the mathematical concept of a sequence.
  • 4. GENERAL PROGRAM public interface List { // List class ADT // Remove all contents from the list, so it is once again empty public void clear(); // Insert "it" at the current location // The client must ensure that the list's capacity is not exceeded public boolean insert(Object it); // Append "it" at the end of the list // The client must ensure that the list's capacity is not Exceeded public boolean append(Object it);
  • 5. // Remove and return the current element public Object remove(); // Set the current position to the start of the list public void moveToStart(); // Set the current position to the end of the list public void moveToEnd(); // Move the current position one step left, no change if already at beginning public void prev(); // Move the current position one step right, no change if already at end public void next(); // Return the number of elements in the list public int length(); // Return the position of the current element public int currPos(); }
  • 6. LINKED LIST  A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers as shown in the below image:  In simple words, a linked list consists of nodes where each node contains a data field and a reference(link) to the next node in the list.
  • 7. WHY LINKED LISTS? Arrays can be used to store linear data of similar types, but arrays have following limitations. 1) The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to the upper limit irrespective of them. 2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted.
  • 8. INSERTING AN ELEMENT IN LINKED LISTS  The new node is always added before the head of the given Linked List. And newly added node becomes the new head of the Linked List. For example if the given Linked List is 10->15- >20->25 and we add an item 5 at the front, then the Linked List becomes 5->10->15->20->25. Let us call the function that adds at the front of the list is push(). The push() must receive a pointer to the head pointer, because push must change the head pointer to point to the new node.
  • 9. INSERTION PROGRAM void push(struct Node** head ref, int new data) { /* 1. allocate node */ struct Node* new node = (struct Node*) malloc(sizeof(struct Node)); /* 2. put in the data */ new node->data = new data; /* 3. Make next of new node as head */ new node->next = (*head ref); /* 4. move the head to point to the new node */ (*head ref) = new node; }
  • 10. DELETING AN ELEMENT IN LINKED LISTS  To delete a node from linked list, we need to do following steps. 1) Find previous node of the node to be deleted. 2) Changed next of previous node. 3) Free memory for the node to be deleted.
  • 11. DELETION PROGRAM void ListDelete(nodeT **listP, elementT value) { nodeT *currP, *prevP; /* For 1st node, indicate there is no previous.*/ prevP = NULL; /* * Visit each node, maintaining a pointer to * the previous node we just visited. */ for (currP = *listP; currP != NULL; prevP = currP, currP = currP>next) { if (currP->element == value) { /* Found it. */ if (prevP == NULL) { /* Fix beginning pointer. */ listP = currP->next; }
  • 12. DELETION Else { /* * Fix previous node's next to * skip over the removed node. */ prevP->next = currP->next; } /* Deallocate the node. */ free(currP); /* Done searching. */ return; } } }
  • 13. ARRAY BASED IMPLEMENTATION  #include<stdio.h> #include<conio.h> #define MAX 10 void create(); void insert(); void deletion(); void search(); void display(); int a,b[20], n, p, e, f, i, pos; void main() { //clrscr(); int ch; char g='y'; do { printf("n main Menu"); printf("n 1.Create n 2.Delete n 3.Search n 4.Insert n 5.Displayn 6.Exit n"); printf("n Enter your Choice"); scanf("%d", &ch);
  • 14. void create() { printf("n Enter the number of nodes"); scanf("%d", &n); for(i=0;i<n;i++) { printf("n Enter the Element:",i+1); scanf("%d", &b[i]); } } void deletion() { printf("n Enter the position u want to delete::"); scanf("%d", &pos); if(pos>=n) { printf("n Invalid Location::"); } else { for(i=pos+1;i<n;i++) { b[i-1]=b[i]; } n--; } printf("n The Elements after deletion"); for(i=0;i<n;i++) { printf("t%d", b[i]); } }
  • 15. void search() { printf("n Enter the Element to be searched:"); scanf("%d", &e); for(i=0;i<n;i++) { if(b[i]==e) { printf("Value is in the %d Position", i); } else { printf("Value %d is not in the list::", e); continue; } } } void insert() { printf("n Enter the position u need to insert::"); scanf("%d", &pos); if(pos>=n) { printf("n invalid Location::"); } else { for(i=MAX-1;i>=pos-1;i--) { b[i+1]=b[i]; }
  • 16. PROGRAM printf("n Enter the element to insert::n"); scanf("%d",&p); b[pos]=p; n++; } printf("n The list after insertion::n"); display(); } void display() { printf("n The Elements of The list ADT are:"); for(i=0;i<n;i++) { printf("nn%d", b[i]); } }
  • 17. ARRAY IN LIST ADT  In computer science, an array data structure, or simply an array, is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key. An array is stored such that the position of each element can be computed from its index tuple by a mathematical formula.The simplest type of data structure is a linear array, also called one- dimensional array.
  • 18. INSERTIND AND DELETING AN ELEMENT IN ARRAY
  • 19. APPLICATIONS OF LIST ADT  Lists can be used to implement Stacks , Queues.  Lists can also be used to implement Graphs. (Adjacency list representation of Graph).  Implementing Hash Tables :- Each Bucket of the hash table can itself be a linked list. (Open chain hashing).  Undo functionality in Photoshop or Word . list of states.  A polynomial can be represented in an array or in a linked list by simply storing the coefficient and exponent of each term.  However, for any polynomial operation , such as addition or multiplication of polynomials , linked list representation is more easier to deal with.  lists are useful for dynamic memory allocation.  The real life application where the circular linked list is used is our Personal Computers, where multiple applications are running.