SlideShare a Scribd company logo
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

What's hot

Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structureTushar Aneyrao
 
Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
naymulhaque
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
swajahatr
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
maamir farooq
 
linked list
linked listlinked list
linked list
Shaista Qadir
 
Linklist
LinklistLinklist
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
Adam Mukharil Bachtiar
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
Doubly Link List
Doubly Link ListDoubly Link List
Doubly Link List
Kashif Memon
 
Singly link list
Singly link listSingly link list
Singly link list
Rojin Khadka
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
Muhazzab Chouhadry
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
Rajkiran Nadar
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
Prof Ansari
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
Khuram Shahzad
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
J.T.A.JONES
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
Muhammad Hammad Waseem
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
student
 

What's hot (20)

Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
linked list
linked listlinked list
linked list
 
Linklist
LinklistLinklist
Linklist
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Doubly Link List
Doubly Link ListDoubly Link List
Doubly Link List
 
Singly link list
Singly link listSingly link list
Singly link list
 
Linked list
Linked listLinked list
Linked list
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
Linked list
Linked listLinked list
Linked list
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 

Similar to Adt of lists

Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
Waf1231
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
AravindAnand21
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
Hanif Durad
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Data structure
Data  structureData  structure
Data structure
Arvind Kumar
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
rohit219406
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
callawaycorb73779
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
ToniyaP1
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
KasthuriKAssistantPr
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
Youssef Elsalhawy
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
ssuser0be977
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Data Structure
Data Structure Data Structure
Data Structure
Ibrahim MH
 

Similar to Adt of lists (20)

Array linked list.ppt
Array  linked list.pptArray  linked list.ppt
Array linked list.ppt
 
Unit7 C
Unit7 CUnit7 C
Unit7 C
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
List
ListList
List
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
Linked list
Linked list Linked list
Linked list
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
 
Ds notes
Ds notesDs notes
Ds notes
 
Data structure
Data  structureData  structure
Data structure
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdfC++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
C++ problemPart 1 Recursive Print (40 pts)Please write the recu.pdf
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
 
dynamicList.ppt
dynamicList.pptdynamicList.ppt
dynamicList.ppt
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Data Structure
Data Structure Data Structure
Data Structure
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 

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.