Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Data Structures Module 1

Good note
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Data Structures Module 1

Good note
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Data Structures

Module-1

Module I: Introduction: Concept of Data Structures, Types of Data Structures,


Linear versus Non Linear Data Structures, Data Structure Operations Array: Linear
Array-Memory representation, insertion and deletion operation, Multidimensional
Arrays-memory representation, Sparse Matrices. Linked List: Concept of Linked
List, Memory representation, Single Linked List - Traversing, Searching,
Insertion,Deletion, Circular Header Linked List , Doubly Linked List - Insertion,
Deletion, Difference of Linked List and Array.

What is a Data Structure?


The logical or mathematical model of a particular organization of data is called a data
structure. It is a particular scheme of organizing related data items.

What are the two categories of data structures?


Data structures are broadly classified in to two.
1. Linear data structures
2. Non Linear data structures

What are linear data structures?


It is a type of Data Structure where the data elements are arranged linearly or sequentially.
Each element in a linear data structure are attached to their next element and previous
element. The structure involves only a single level- allowing a user to traverse all its
components in a single run. Examples of linear data structures are stack, array, linked list,
queue, etc.

What are non-linear data structures?


It is a form of data structure where the data elements are arranged in a non-linear manner. In
a non-linear data structure, the data elements connect to each other hierarchically. Since, the
elements are arranged in multiple levels, it is not easy to traverse a non-linear data structure.
The users need multiple runs to traverse them completely. Examples of non-linear data
structures are map, graph, tree, set, dictionary etc.

Explain the difference between Linear and Non-linear Data Structures


Parameter Linear Data Structure Non-Linear Data Structure
In a linear data structure, the data In a non-linear data structure, the data
Arrangement
elements connect to each other elements connect to each other
of Data
sequentially. A user can transverse hierarchically. Thus, they are present
Element
each element through a single run. at various levels.
The non-linear data structures are
Complexity of
The linear data structures are comparatively difficult to implement
Implementatio
comparatively easier to implement. and understand as compared to the
n
linear data structures.
A user can find all of the data One can find all the data elements at
Levels elements at a single level in a linear multiple levels in a non-linear data
data structure. structure.
Traversal You can traverse a linear data It is not easy to traverse the non-linear
structure in a single run. data structures. The users need
multiple runs to traverse them
completely.
It is not very memory-friendly. It The data structure is memory-
Utilization of
means that the linear data structures friendly. It means that it uses memory
Memory
can’t utilize memory very efficiently. very efficiently.
The time complexity of this data
structure is directly proportional to its Non-linear data structure’s time
Complexity of
size. It means that the time complexity often remains the same
Time
complexity increases with increasing with an increase in its input size.
input size.
Linear data structures work well Non-linear data structures work
Applications mainly in the development of mainly well in image processing and
application software. Artificial Intelligence.
Examples List, Array, Stack, Queue. Graph, Tree,Set,Dictionary

Explain different linear data structures

1. Array: Array is a sequence of n items of the same data type that are stored
contiguously in computer memory and made accessible by specifying an index. The
index usually varies from 0 to n-1. Each element in array can be accessed randomly.
Strings are special type of arrays in which each element is a character. Strings
composed of zeroes and ones are called binary strings or bit strings.
2. Linked List: Linked list is a sequence of zero or more elements called nodes. Each
node is comprised of a data component and a pointer component. The pointer points
to the adjacent element. In a singly linked list, each node has a pointer to the next
element. In a doubly linked list, each node has a pointer to the next node as well as a
pointer to the previous node. To access a particular node in a singly linked list, we
have to start with the first node and traverse the pointer chain until the particular node
is reached. A doubly linked list can be traversed in both directions, from beginning to
end or end to beginning.
3. Stack: A stack is a type of list in which insertion and deletion can be done only at one
end. This end is called top. Insertion of an element into a stack is called push
operation and deletion of an element from the stack is called pop operation. Since,
push and pop can be done only at the top, the stack works in a Last-in-First-out
fashion. Thus stack is also called a LIFO data structure.
4. Queue: A queue is a list from which elements are deleted from one end called the
front and new elements are added to the other end called the rear. Thus, a queue
operates in a first-in-First-Out fashion. Queue is also called a FIFO data structure. A
priority queue is a queue in which each element in the queue has a priority associated
with it, and an element with the highest priority will be deleted first.

Explain different non-linear data structures


1. Graph: A graph is a collection of points in the plane, called ‘vertices’ or ‘nodes’.
The vertices are connected by line segments called ‘edges’ or ‘arcs’. Formally , a
graph G=( V,E) is defined by a pair of two sets : a finite non empty set V of items
called vertices and a set E of pairs of these items called edges. A directed graph
(or digraph) is a set of vertices and a collection of directed edges that each
connects an ordered pair of vertices. We say that a directed edge points from the
first vertex in the pair and points to the second vertex in the pair. If the edges in a
graph are undirected, it is called undirected graph. A graph with every pair of its
vertices connected by an edge is called a complete graph. A graph with relatively
few edges missing is called a dense graph. A graph with few edges relative to the
number of its vertices is called sparse graph. A weighted graph is a graph
whose edges have weights or costs assigned to them. A graph is said to be
connected if every pair of the graph is connected by an edge. A graph with no
cycles is called an acyclic graph. A cycle is a path that starts and ends at the same
vertex and does not traverse the same edge more than once.
2. Tree: a tree is a connected acyclic graph. The number of edges in a tree is always
one less than the number of its vertices. A graph that has no cycles but is not
necessarily connected is called a forest in which each of its connected components
is a tree. Root of a tree is the vertex from which the hierarchical structure begins.
When depicting a rooted tree, the root is placed on the top level (level 0) of the
tree. For any vertex v in a Tree , all the vertices on the simple path from root to
that vertex is called ancestors of v. Most immediate ancestor of a vertex is called
its parent and immediate successor of a vertex is called its child. Vertices that
have the same parent are called siblings. A vertex with no children is called a
leaf. The depth of a vertex is the length of the simple path from the root to that
vertex. The height of a tree is the length of the longest simple path from the root
to a leaf. A binary tree is an ordered tree in which every vertex has no more than
two children and each child is designated as a left child or a right child.
3. Set: A set is an unordered collection of distinct items called elements. A set can be
specified either by an explicit listing of its elements or by specifying a property
that each element in the set must satisfy. The most important set operations are (i)
checking membership of an item in the set (ii) set union and (iii) set intersection.
4. Dictionary: A dictionary is an unordered collection of items in which each item is
a <key,value> pair. The keys in a dictionary must be distinct. Most important
operations on a dictionary are (i) searching for a given item (ii) adding a new item
and (iii) deleting an item.

Explain different Data structure operations


The data appearing in data structures are processed by means of certain operations. The
following four operations are the most frequently used operations.
1. Traversing: Accessing each record (node) exactly once so that certain items in the
record may be processed. Accessing and processing a record is also known as visiting
the record.
2. Searching: Finding the location of the record with a given key value, or finding the
locations of all records which satisfy one or more conditions.
3. Inserting: Adding a new record to the structure.
4. Deleting: Removing a record from the structure
The following two special operations are also used on data structures
1. Sorting: Arranging the records in some logical order like alphabetical order for character
data , ascending order or descending order for numerical data etc.
2. Merging: Combining the records in two different sorted data structures into single sorted
structure.

What is an Array?
Array is a sequence of n items of the same data type that are stored contiguously in
computer memory and made accessible by specifying an index. The index usually varies
from 0 to n-1. Each element in array can be accessed randomly.
What is a linear array?
A linear array is a list of a finite number n of homogenous data elements such that the
elements of the array are referenced by an index. Indexes are also called subscripts. Most
computer languages supports 0-based indexing where as some computer languages support
1- based indexing. In 0-based indexing, index values varies from 0 to n-1. In 1-based
indexing, index values varies from 1 to n. The elements of a linear array are stored in
successive memory locations.

Explain how linear arrays are represented in memory


Let LA be a linear array in the memory of the computer. Let LOC(LA[K]) denote the
address of the element LA[K] of the array LA.The computer does not need to keep track of
the address of every element of LA, but needs to keep track only of the address of the first
element of LA denoted by Base(LA) and called the base address of LA. Using this base
address, the computer can calculate the address of any element of LA by the following
formula:
LOC(LA[K]) = Base(LA)+w(K – lower bound) ,
where w is the number of words per memory cell for the array LA. Given any subscript K,
one can locate and access the content of LA[K] without scanning any other element of LA.

Write an algorithm to insert a value in to an Array.


Given below is an algorithm to insert an element k at the position m of an array A of size n.
Step 1: Locate an empty position in the array after the mth position.
Step 2: If sucha position (say p) is found, element k can be inserted, go to step 4.
Step 3: No empty place in the array. So can’t be inserted. STOP.
Step 4: For i=p to m+1 step -1.
Move i-1st element to ith element.
End For
Step 5: Insert the element at the now empty position
Step 6: STOP.

Write a C program to implement the above algorithm


/* A progran to insert a value in to an Array */
#include<stdio.h>
#include<conio.h>
#define size 50
void main()
{
int a[size],k,n,i,m;
clrscr();
printf("Enter the nunber of elenents : ");
scanf("%d",&n);
printf("Enter the elenents\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the value to be inserted : ");
scanf("%d",&k);
printf("Enter the index position in which the value to be inserted : ");
scanf("%d",&m);
if(m>n)
printf("Insertion not possible\n");
else
{
for(i=n;i>m;i--)
{
a[i]=a[i-1];
}
a[i]=k;
n++;
printf("The final List is \n");
for(i=0;i<n;i++)
{
printf("%4d",a[i]);
}
}
getch();
}

Write an Algorithm to delete an element from an Array


The following algorithm deletes the Kth element from an array LA and assigns it to a
variable ITEM.
Here LA is a linear array with N elements and K is a positive integer such that K<=N.
Step 1: Set ITEM=LA[K]
Step 2: Repeat for J=K to N-1:
/*Move J+1st element upward*/
Set LA[J]=LA[J+1]
End of Loop
Step 3: /* Reset the number of elements in LA */
Set N=N-1
Step 4: STOP.

Write a C program to implement the above algorithm

/* A program to delete an element from an Array */


#include<stdio.h>
#include<conio.h>
#define size 20
void main()
{
int list[size],loc,i,m,back;
clrscr();
printf("Enter the number of elements : ");
scanf("%d",&m);
printf("Enter the elements\n");
for(i=0;i<m;i++)
{
scanf("%d",&list[i]);
}
printf("Enter the index position from where the deletion to be done : ");
scanf("%d",&loc);
if(loc > m)
printf("Deletion not possible\n");
else
{
for(i=loc;i<m;i++)
{
list[i]=list[i+1];
}
m--;
printf("The final list is \n");
for(i=0;i<m;i++)
{
printf("%4d",list[i]);
}
}
getch();
}

Representation of Two-Dimensional Arrays in Memory


Let A be a two-dimensional m x n array. The array will be represented in memory by a
block of sequential memory locations. Specifically, the programming language will store
the array A either (1) column by column, is what is called column-major order, or (2) row
by row, in row-major order. Particular representation used depends upon the programming
language. For a linear array LA, the computer does not keep track of the address of every
element, but does keep track of the address of the first element of LA. The computer uses a
formula to find out the address of every other element in the array..
Similarly, for a two-dimensional m x n array A. the computer keeps track of the
address of the first element A[1, 1] of A (Base(A)) and computes the address LOC(A[J, K])
of A[J,K] using the formula
For column major order:
LOC(A[J. K]) = Base(A) + w[M(K - 1) + (J - 1)]
For row major order :
LOC(A[J, K]) = Base(A) + w[N(J - 1) + (K - 1)]
Here, w denotes the number of words per memory location for the array A.

What is a sparse matrix?


If most of the elements of the matrix have 0 value, then it is called a sparse matrix.
Representing a sparse matrix by a 2D array leads to wastage of lots of memory as zeroes in
the matrix are of no use in most of the cases. So, instead of storing zeroes with non-zero
elements, we only store non-zero elements in the form of triplets <Row, Column, value>. A
sparse matrix can be represented in two ways:
1. Array representation:
2D array is used to represent a sparse matrix in which there are three columns named
as Row (Index of row, where non-zero element is located) , Column ( Index of
column, where non-zero element is located) and Value ( Value of the non-zero
element located at index (row,column))
2. Linked list representation:
In linked list, each node has four fields. These four fields are row, column, value and
a pointer to the next node.
This type of representation has the following advantages:
a) Storage: There are lesser non-zero elements than zeros and thus lesser memory can be
used to store only those elements.
b) Computing time: Computing time can be saved by logically designing a data structure
traversing only non-zero elements.

Linked List

A linked list is a linear data structure, in which the elements are not stored at contiguous
memory locations. Each element in a linked list are known as nodes. The nodes in a linked
list are linked using pointers. Each node stores the data and the address of the next node.
The last node in a linked list points to a special pointer called NULL. We use a pointer
variable to point to the first node in the list. Starting with this pointer, we can traverse the
entire linked list by following the pointer links of each node.

What are the differences between arrays and linked lists?

ARRAY LINKED LIST


Static data structure: Number of elements Dynamic data structure: Number of nodes
of array to be declared at compile time, need not be declared, memory allocated at
memory allocated at compile time run-time

Random data structure: Any element can Sequential data structure: Each node can
be directly accessed by referring to its be accessed only after traversing through
index. Time taken to access any element is all previous nodes. Time taken to access a
independent of its position. Can be used node depends on its position (Max time for
for both sequential and random access last node, minimum time for first one).
applications (e.g. mark processing or bank Suitable only for sequential access
balance enquiry) applications (e.g. mark processing)

No memory overhead Array of 10 int takes Memory overhead (one pointer per node)
104=40 bytes Array of 10 char takes Linked list of 10 int takes 10(4 + 41= 80
10.1=10 bytes bytes Linked list of 10 char takes 1041 +
4) = 50 bytes

Contiguous memory required Can work with non-contiguous memory

Insertion and deletion of array elements Insertion and deletion of list nodes
requires all succeeding elements to be requires only the preceding and
shifted down or up. succeeding nodes to be modified.

Arrays are comparatively easy to program. Linked list programming is comparatively


They can be handled efficiently using for difficult involving pointers.
loops

What are the disadvantages of linked lists?


1. Random access is not allowed. We have to access elements sequentially starting from
the first node (head node). So we cannot do certain standard algorithms like binary
search with linked lists.
2. Extra memory space for a pointer is required with each element of the list.
3. Not cache friendly. Since array elements are contiguous locations, there is locality of
reference which is not there in case of linked lists.

What are the different types of linked lists?


1. Linked List or singly linked list: In this type of linked list each node has a pointer to
the next node. Traversal is possible only from the beginning to end, in one direction
only.
2. Doubly Linked List: In this type of linked list, each node has two pointers, one
pointing to the next node and the other one pointing to the previous node. We can
traverse a doubly linked list in both directions from beginning to end in forward
direction and from end to beginning in backward direction.
3. Circular Linked List: In this type of linked list, the last node of the linked list contains
the link of the first/head node of the linked list in its next pointer and the first/head
node contains the link of the last node of the linked list in its prev pointer.

Representation of Linked Lists


Each node in a Linked list consists of at least two parts (i) A Data Item (we can store integer,
strings, or any type of data) (ii) Pointer (Or Reference) to the next node (connects one node to
another) or an address of another node. A node can be represented using a self-referential
structure. Below is an example of a linked list node with integer data.

struct Node {
int data;
struct Node* next;
};

A linked list is represented by a pointer to the first node of the linked list. The first node is
called the head of the linked list. If the linked list is empty, then the value of the head points
to NULL. To create a linked list, first we dynamically allocate memory for the head node.
Consecutive nodes are created by dynamically allocating memory to the *next pointer of
each node. The *next pointer of last node will point to NULL.

Write an algorithm to create a linked list to store integer data

Step 1: Declare pointers ‘first’ and ‘current’ of type ‘struct node’


Step 2: Allocate memory to first node. Assign current=first.
Step 3: while (current != NULL ) repeat steps 4 and 5
Step 4: Read data for the current node.
If data==0 then
Assign NULL to current->next
Else
Allocate memory for current->next
Step 5: Assign current=current->next , so that current points to the next node
Step 6: Stop

Write an algorithm to traverse a linked list


Step 1: Set current=first, so that current points to first node
Step 2: while (current != NULL) repeat steps 3 and 4
Step 3: print current->data
Step 4: Set current=current->next , so that current points to the next node
Step 5: STOP

Write a C program to Create and Traverse a Linked List

#include<stdio.h>
#include<alloc.h>
#include<conio.h>
struct node{
int data;
struct node *next;
};
struct node *first,*current;
int temp;
void main()
{
clrscr();
first=(struct node *)malloc(sizeof(struct node));
current=first;
printf("Enter data for the nodes. Enter 0 to stop\n");
while(current!=NULL)
{
scanf("%d",&temp);
current->data=temp;
if(temp==0)
current->next=NULL;
else
current->next=(struct node *)malloc(sizeof(struct node));
current=current->next;
}
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
getch();
}

Write an algorithm to search a Linked List

Step 1: Read the search key


Step 2: Set current=first
Step 3: while current != NULL repeat step 4
Step 4: if key==current->data then:
Print ‘Data Found’ and go to Step 5
Else
Current=current->next , so that current points to next node
Step 5: Stop

Write a program to search a Linked List

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node{
int data;
struct node *next;
};
struct node *first,*current;
void main()
{
int count,search;
clrscr();
first=(struct node *)malloc(sizeof(struct node));
current=first;
printf("Enter the data. enter 0 to stop\n");
while(1)
{
scanf("%d",&current->data);
if(current->data==0)
{
current->next=NULL;
break;
}
current->next=(struct node *)malloc(sizeof(struct node));
current=current->next;
}
printf("Enter the number to serach\n");
scanf("%d",&search);
count=0;
current=first;
while(current->next!=NULL)
{
count++;
if(current->data==search)
{
printf("Found at Node No:%d\n",count);
}
current=current->next;
}
getch();
}

Write an algorithm to insert a node to a Linked List


Step 1: Read ‘key’ after which the new data to be inserted
Step 2: Traverse to the node which contains the data ‘key’.
Step 3: Set ‘current’ points to this node.
Step 4: Create a new_node.
Step 5: Read new_node->data.
Step 6: Set new_node->next=current->next and
Set current->next=temp ,
so that new_node is inserted between current node and its next node.
Step 7: STOP.

Write a program to insert a node to a linked list


/* Program to insert a node in a linked list, after a given node */
#include<stdio.h>
#include<alloc.h>
#include<conio.h>
struct node{
int data;
struct node *next;
};
struct node *first,*current,*temp;
void main()
{
int after;
clrscr();
first=(struct node *)malloc(sizeof(struct node));
current=first;
printf("Enter data\n");
while(current!=NULL)
{
scanf("%d",&current->data);
if(current->data==0)
current->next=NULL;
else
current->next=(struct node *)malloc(sizeof(struct node));
current=current->next;
}
printf("The Linked List is \n");
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
printf("\nEnter the data after which the node to be inserted : ");
scanf("%d",&after);
current=first;
while(current!=NULL && current->data!=after)
{
current=current->next;
}
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter the data : ");
scanf("%d",&temp->data);
temp->next=current->next;
current->next=temp;
printf("The Linked List after insertion\n");
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
getch();
}

Write an algorithm to delete a node from a Linked List.


Step 1: Read the ‘key’ to delete.
Step 2: while current != NULL and current->data != key repeat step 3 and 4
Step 3: Set prev=current
Step 4: current=current->next
Step 5: Set prev->next = current->next ,
so that the node just before ‘current’ points to the node just after ‘current’.
Step 6: STOP

Write a program to delete a node from a Linked List

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node{
int data;
struct node *next;
};
struct node *first,*current,*prev;
int a;
void main()
{
clrscr();
first=(struct node *)malloc(sizeof(struct node));
current=first;
printf("Enter the data. 0 to stop\n");
while(1)
{
scanf("%d",&current->data);
if(current->data==0)
{
current->next=NULL;
break;
}
else
{
current->next=(struct node *)malloc(sizeof(struct node));
current=current->next;
}
}
printf("Linked List is \n");
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
printf("Enter the data to delete\n");
scanf("%d",&a);
current=first;
while(current!=NULL && current->data!=a)
{
prev=current;
current=current->next;
}
if(current!=NULL)
prev->next=current->next;
printf("Linked List is \n");
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
getch();
}
Explain header linked lists

Write an algorithm to Create a doubly linked list


Write a Program to create a doubly linked list, perform forward traversal and
backward traversal

/* program to craete a doubly linked list, forward traversal


and backward traversal*/

#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node{
struct node *prev;
int data;
struct node *next;
};
struct node *first,*current,*temp,*last;
int a,d;
void main()
{
clrscr();
first=(struct node *)malloc(sizeof(struct node));
first->prev=NULL;
current=first;
printf("Enter data. 0 to stop\n");
while(1)
{
scanf("%d",&current->data);
if(current->data==0)
{
current->next=NULL;
last=current;
break;
}
else
{
current->next=(struct node *)malloc(sizeof(struct node));
current->next->prev=current;
current=current->next;
}
}
printf("Forward Traversal\n");
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
printf("Backward Traversal\n");
current=last->prev;
while(current!=NULL)
{
printf("%d\n",current->data);
current=current->prev;
}
getch();
}

Explain how to insert a node in a doubly linked list


Write a program to insert a node in a doubly linked list

/* program to insert a node in a doubly linked list, after a given node */


#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node{
struct node *prev;
int data;
struct node *next;
};
struct node *first,*current,*temp;
int a,d;
void main()
{
clrscr();
first=(struct node *)malloc(sizeof(struct node));
first->prev=NULL;
current=first;
printf("Enter data. 0 to stop\n");
while(1)
{
scanf("%d",&current->data);
if(current->data==0)
{
current->next=NULL;
break;
}
else
{
current->next=(struct node *)malloc(sizeof(struct node));
current->next->prev=current;
current=current->next;
}
}
printf("The Linked List is\n");
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
printf("Enter the data after which new node to be created\n");
scanf("%d",&a);
current=first;
while(current!=NULL && current->data!=a)
current=current->next;
temp=(struct node *)malloc(sizeof(struct node));
printf("Enter data for the new node\n");
scanf("%d",&temp->data);
current->next->prev=temp;
temp->next=current->next;
temp->prev=current;
current->next=temp;
printf("List after insertion\n");
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
getch();
}

Explain how to delete a node from a doubly linked list


Write a program to delete a node from a doubly linked list
/* program to delete a node in a doubly linked list whose data is given */
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node{
struct node *prev;
int data;
struct node *next;
};
struct node *first,*current,*temp;
int a,d;
void main()
{
clrscr();
first=(struct node *)malloc(sizeof(struct node));
first->prev=NULL;
current=first;
printf("Enter data. 0 to stop\n");
while(1)
{
scanf("%d",&current->data);
if(current->data==0)
{
current->next=NULL;
break;
}
else
{
current->next=(struct node *)malloc(sizeof(struct node));
current->next->prev=current;
current=current->next;
}
}
printf("The Linked List is\n");
current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
printf("Enter the data to be deleted \n");
scanf("%d",&a);
current=first;
while(current!=NULL && current->data!=a)
{
current=current->next;
}
current->prev->next=current->next;
current->next->prev=current->prev;
current->prev=NULL;
current->next=NULL;

printf("List after deletion\n");


current=first;
while(current->next!=NULL)
{
printf("%d\n",current->data);
current=current->next;
}
getch();
}

**********

You might also like