Practical File: Data Structures (TCT-201)
Practical File: Data Structures (TCT-201)
(TCT-201)
Practical File
(Session: 2023-2024)
INDEX
S.NO. PRACTICAL NAME PAGE NO.
1. Write a program in c to traverse through elements of an array 1
2. 3
Write a program in c to insert an element at the beginning of an array
3. 5
Write a C program to delete an element at the beginning of an array
4. 7
Write a C program to search for an element in the array using linear search
5. Write a C program to sort an array (Insertion sort) 9
6. Write a C program to perform binary search on sorted array 11
7. Write a C program to perform merge sort on an array 13
8. 17
Write a program in c to traverse through the elements of a linked list
9. Write a C program to insert an element in the linked list 22
10. Write a C program to delete an element from the linked list 25
11. Write a program in c to traverse through the elements of a doubly linked 28
list
12. Write a program in c to insert an element to a doubly linked list 32
13. 36
Write a C program to delete an element from a doubly linked list
Time Complexity
O(n) //since one traversal of the array is required to complete all operations hence overall time
required by the algorithm is linear.
Space Complexity
O(1)// since no extra array is used so the space taken by the algorithm is constant.
INPUT:
#include<stdio.h> int
main()
{
//Initialize array and size variable
int arr[10],size; //Enter length
of array printf("Enter size of the
array:"); scanf("%d",&size);
//Inserting elemnts in the array printf("Enter
the elements of the array:");
for(int i=0;i<size;i++){
scanf("%d",&arr[i]);
}
return 0;
1
}
OUTPUT:
2
2. INSERTION IN AN ARRAY
Objective-
To insert an element in the given position in an array
Theory-
STEP 1: First get the element to be inserted, say num.
STEP 2: Then get the position at which this element is to be inserted, say pos.
STEP 3: Then shift the array elements from this position to one position forward
(towards right), and do this for all the other elements next to pos STEP 4: Insert the
element num now at the position pos, as this is now empty.
Time Complexity
The best-case complexity is O(1), if the element we want to insert at the end of the
array . The worst-case time complexity is O(n), if we want to insert the element at the
first position of the array then we have shifted all the rest element by 1 hence the shift
will occur n times. Hence the worst-case time complexity will be O(n).
Space Complexity
Insertion requires only a fixed amount of extra space for the key variables. As a result,
the space complexity of insertion is O(1). INPUT:
#include<stdio.h>
int main()
{
int a[100],n,i,j,k,num,pos; printf("Enter the number of
elements in the array="); scanf("%d",&n);
printf("Enter the elements in the array=");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the element to be inserted=");
scanf("%d",&num);
printf("Enter the position to be inserted=");
scanf("%d",&pos); printf("The original
array=\n"); for(i=0; i<n;i++)
{
printf("%d\t",a[i]);
} j=n;
n=n+1;
while(j>=pos)
{
a[j+1] =a[j];
j--;
}
a[pos]=num;
printf("\nThe array after insertion=\n"); for(i=0;
i<n;i++)
{
3
printf("%d\t",a[i]);
}
}
OUTPUT:
3. DELETION IN AN ARRAY
Objective-
To delete an element from the given position in an array
Theory-
STEP 1: First, get the position of the element which needs to be deleted, say pos.
STEP 2: Then shift the array elements from this position to one position back
(towards left), and do this for all the other elements next to pos.
STEP 3: Print the array.
Time Complexity
The worst-case time complexity is O(n), if we want to delete the element at the first
position of the array then we have shifted all the rest element by 1 hence the shift
will occur n times. Hence the worst-case time complexity will be O(n).
Space Complexity
Deletion requires only a fixed amount of extra space for the key variables. As a result,
the space complexity of insertion is O(1). INPUT:
4
#include<stdio.h>
int main()
{
int a[100],n,pos,i,j; printf("Enter the number of
the elements in the
array=");
scanf("%d",&n);
printf("Enter the elements in the array=");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("The original array="); for(i=0;i<n;i++)
{
printf("\t%d",a[i]);
} printf("\nEnter the position of the element to be deleted from the array=");
scanf("%d",&pos); j=n-1; while(j>=pos)
{
a[pos]=a[pos+1];
pos++;
}
5
printf("\nThe array after deletion=");
for(i=0;i<n-1;i++)
{
printf("\t%d",a[i]);
}
return 0; }
OUTPUT:
6
4. LINEAR SEARCH
Objective
To check each element of the list sequentially until a match is found or the whole list has
been searched.
Theory
The algorithm of the program is as follows
STEP 1: Input the array from the user and the element to be searched.
STEP 2: Initialize the value of flag = 0.
STEP 3: Using for loop the element to be searched is compared to all other elements of the
array.
STEP 4: If it finds an equal match of the element then it assigns the value of ‘i’ to ‘loc ‘and
also assigns flag = 1.
STEP 5: Finally, if flag = 1, then it is printed as “the element is in the list and its position is
(position)” else it is printed as “the element is not found”.
Time Complexity
The best-case complexity is O(1) if the element is found in the first iteration of the loop.
The worst-case time complexity is O(n), if the search element is found at the end of the
array or the element to be search is not present in the array, provided the size of the array is
n.
Space Complexity
The linear search only need one element need (that is the variable you used to compare
with all the elements in the array), so no matter how big or small your array is, the
algorithm only consumes the same amount of memory for all input, and thus is space
complexity is O(1). INPUT:
#include<stdio.h> void
print_array(int arr[],int n)
{
//Printing the array int i;
printf("The entered array is \n");
for(i=0;i<n;i++) { printf("%d
",arr[i]);
}
}
void linear_search(int arr[],int item,int n){
//Linear search int
flag,i,loc; flag = 0 ;
for (i = 0 ; i < n ; i++) {
if ( arr[i] == item ) {
loc= i ;
7
flag = 1; break ;
}
}
if ( flag == 0){ printf("%d element is not in the
array \n",item);
}
else{ printf("%d element is present in the array at position %d\n",item , loc
+1); }
}
int main(){ int
i,n,loc,item,flag;
int arr[n];
//Entering the length of the array printf("Enter the
length of the array : "); scanf("%d",&n);
//Taking values from the user for(i=0;i<n;i++)
{ printf("Enter the %d element of the array : ",i+1);
scanf("%d",&arr[i]);
}
print_array(arr,n); printf("\n"); printf("Enter the
element you want to check : "); scanf("%d",&item);
linear_search(arr,item,n);
}
OUTPUT:
5. INSERTION SORT
Objective- To sort elements in an array using insertion sort.
Theory-
STEP 1: Iterate from arr[1] to arr[N] over the array.
STEP 2: Compare the current element (key) to its predecessor.
STEP 3: If the key element is smaller than its predecessor, compare it to the elements
before. Move the greater elements one position up to make space for the swapped element.
Time Complexity
Suppose, an array is in ascending order, and you want to sort it in descending order. In this
case, worst case complexity occurs.
Each element has to be compared with each of the other elements so, for every
nth element, (n-1) number of comparisons are made.
Thus, the total number of comparisons = n*(n-1) ~ n2 The
2
worst-case complexity is O(n ).
When the array is already sorted, the outer loop runs for n number of times whereas the
inner loop does not run at all. So, there are only n number of comparisons. Thus,
complexity is linear. The best-case complexity is O(n).
Space Complexity
Insertion sort requires only a fixed amount of extra space for the key variables.
As a result, the space complexity of bubble sort is O(1). INPUT:
#include<stdio.h> int
main()
{ int i,j,a[100],n,key; printf("Enter the number
of elements in the array=");
scanf("%d",&n);
printf("Enter the elements in the array=");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<n;i++)
{
key=a[i]; j=i-1;
while(j>=0&&a[j]>key)
{
a[j+1]=a[j];
j--; }
9
a[j+1]=key;
}
printf("The array after sorting=\n"); for(i=0;i<n;i+
+)
{
printf("%d\t",a[i]);
}
return 0;
}
OUTPUT:
10
6. BINARY SEARCH
Objective- To search an element in the sorted array
Theory-
STEP 1: Find the middle element of array. Using, middle = initial_value + end_value / 2.
STEP 2: If middle = element, return ‘element found’ and index.
STEP 3: If middle > element, call the function with end_value = middle - 1.
STEP 4: If middle < element, call the function with start_value = middle + 1.
STEP 5: Exit.
Time Complexity
In Binary search, best case occurs when the element to search is found in first
comparison, i.e., when the first middle element itself is the element to be searched. The
best-case time complexity of Binary search is O(1). In Binary search, the worst case
occurs, when we have to keep reducing the search space till it has only one element. The
worst-case time complexity of Binary search is O(log 2 n).
Space Complexity
In an iterative implementation of Binary Search, the space complexity will be O(1).
This is because we need two variables to keep track of the range of elements that are
to be checked. INPUT:
#include<stdio.h
>
int main()
{
int arr[100];
int i,a,j,count=0,n,start,end,mid; printf("Enter
the number of elements in the array=");
scanf("%d",&a);
printf("Enter the elements in the array=");
for(i=0;i<a;i++)
{
scanf("%d",&arr[i]);
}
printf("Enter the element to
besearched="); scanf("%d",&n);
start=0; end=a-1;
mid=(start+end)/2;
if(arr[mid]==n)
{ printf("The element is present in the array");
11
return 0;
} else
{
while(start<=end)
{
if(arr[mid]<n) {
start=mid+1; mid=(start+end)/2;
if(arr[mid]==n)
{ printf("The element is present in the array");
count=1;
return 0;
} }
else
{
end=mid-1;
mid=(start+end)/2;
if(arr[mid]==n)
{ printf("The element is present in the array"); count=1;
return 0;
}
}
}
} if(count==0)
printf("The number is not present in the array");
return 0;
}
OUTPUT:
12
7. MERGE SORT
Objective-
To sort the elements of the array
Theory-
The algorithm of the program is as follows
STEP 1: Declare an array and left, right and middle variable. STEP
STEP 3: Stop
Time Complexity
Merge Sort is quite fast, and has a time complexity of O(n*log n). It is also a stable sort,
which means the "equal" elements are ordered in the same order in the sorted list.
As we have already learned in Binary Search that whenever we divide a number into half
in every step, it can be represented using a logarithmic function, which is log n and the
number of steps can be represented by log n + 1
Also, we perform a single step operation to find out the middle of any subarray, i.e. O(1).
And to merge the subarrays, made by dividing the original array of n elements, a
running time of O(n) will be required.
Hence the total time for mergeSort function will become n(log n + 1), which gives us
a time complexity of O(n*log n). Worst Case Time Complexity [ Big-O ]: O(n*log
n)
Best Case Time Complexity [Big-omega]: O(n*log n)
Space Complexity
The space complexity of the program is O(n). In merge sort all elements are
13
copied into an auxiliary array. So, n auxiliary space is required for merge sort. INPUT:
#include <stdio.h>
#include<stdlib.h>
14
{ if (l < r) { int m
= l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
int main()
{ int n,i;
int arr[n];
// Entering the length of the array printf("Enter
the length of the array : ");
scanf("%d",&n);
mergeSort(arr, 0, n - 1);
15
OUTPUT:
8. TRAVERSING A LINKED LIST
Objective:
To traverse through the elements of the linked list
Theory:
16
1. Create a temporary variable for traversing. Assign reference of head node to it, say
temp= head
2. Repeat below step till temp!=NULL.
3. Temp->data contains the current node data. You can print it or can perform some
calculation on it.
4. Once done, move to next node using temp=temp->data.
5. Go back to 2nd step
Time Complexity:
The time complexity is O(√N) where N is block of continuous elements being read. As
Linked List elements are not contiguous, each element access incur a Time Complexity of
O(√N). This is an overhead compared to Array where the overhead to encountered only
once.
Space Complexity:
The Space Complexity of the above Linked List operations is O(1). This is because we do
not need extra space beyond a fixed number of variables. For some operations, you may
need extra space of the order of O(N). For example, sorting a Linked List using a sorting
algorithm that is not in-place.
INPUT:
#include <stdio.h>
17
}*head;
return 0;
*newNode, *temp;
== NULL)
exit(0);
+)
18
newNode = (struct node *)malloc(sizeof(struct
if(newNode == NULL)
break;
newNode
19
newNode->next = NULL; // Make sure new node points to NULL
traverseList()
if(head == NULL)
printf("List is empty.");
return;
temp = head;
while(temp != NULL)
20
OUTPUT:
Theory
The algorithm of the program is as follows
INSERTION AT FRONT
STEP 1: Create a new node
STEP 2: Assign its data value
STEP 3: Assign newly created node’s next ptr to current head reference. So, it points to
the previous start node of the linked list address STEP 4: Change the head reference to
the new node’s address.
INSERTION AT A POSITION
STEP 1: First we will create a new node named by newnode and put the position where u
want to insert the node.
STEP 2: Now give the address of the new node in previous node means link the new
node with previous node.
STEP 3: After this, give the address of current node in new node means link your
new node also with current node. INSERTION AT THE END
STEP 1: Create a new node
STEP 2: Assign its data value
STEP 3: Assign its next node to NULL as this will be the last(tail) node
STEP 4: Check if the list is empty A) Change
the head node to the new node
STEP 5: If not then traverse till the last node
STEP 6: Assign the last node’s next pointer to this new node
STEP 7: Now, the new node has become the last node.
Time Complexity
The time complexity is O(n). We have a pointer to the head and we have to transverse the
list to the end node to insert the new data, so the while loop in line 11 will run n times
where n is the number of nodes already stored in the linked list. So here the most
dominating term is n, hence the time complexity of the above algorithm will be O(n).
Space Complexity
It requires only a fixed amount of extra space for the key variables. As a result, the space
complexity of the above algorithm is O(1).
22
INPUT:
# include<stdio.h> #
include<stdlib.h>
struct node { int
data ; struct node
*link ;
};
// Printing function void print(struct
node *ptr){ printf("The linked list is
: "); while (ptr!= NULL)
{ printf("%d ",ptr->data);
ptr=ptr->link;
}
printf("\n");
}
// Inserting at the starting of the linked list struct node* insert_at_start(int
data,struct node* head){ struct node *start; start=(struct node
*)malloc(sizeof(struct node)); start->data=data; start->link=head;
head=start; return head;
}
// Inserting at the end of the linked list struct node* insert_at_end(int data,struct node* head){ struct
node *end,*ptr; end=(struct node *)malloc(sizeof(struct node)); end->data=data; end-
>link=NULL; ptr=head; while (ptr->link!= NULL){ ptr = ptr->link;
} ptr-
>link=end;
return head;
}
// Inserting element at the user want position struct node* insert_at_position(int data,int
position,struct node* head){ int i
;
struct node *between,*ptr; between=(struct node
*)malloc(sizeof(struct node)); between->data=data;
ptr=head; for(i=1;i<(position1);i++){ ptr=ptr->link;
} between->link=ptr>link;
ptr-
>link=between; return
head;
}
23
int main(){ int c,data,pos, choice; struct node
*head , *ptr; head = (struct node
*)malloc(sizeof(struct node)); printf("What value
you want to enter : ");
scanf("%d",&data); head-
>data=data; head->link=NULL;
print(head); do{
printf("\nWhat value you want to enter : ");
scanf("%d",&data); printf("What operation you
want to perform\
\n 1.Insert at the beginning\
\n 2.Insert at between \
\n 3.Insert at the end\n");
24
Objective
To delete an element from the beginning, end or from a given position from the linked list
Theory
DELETION AT THE BEGINNING
STEP 1: Assign next node in a linked list as the new head
STEP 2: Free previous head
DELETION AT THE END
STEP 1: Search the Node to be deleted and call it temp
STEP 2: Store previous node call is as previous
STEP 3: Assign previous->next to temp->next
STEP 4: In this case, the temp->next will be Null so no difference from deletion at middle
STEP 5: Free(temp)
DELETION AT A POSITION
STEP 1: Search the Node to be deleted and call it temp
STEP 2: Store previous node call is as previous
STEP 3: Assign previous->next to temp->next
STEP 4: Free(temp)
Time Complexity
The time complexity is O(n), as in the worst case when the last element is to be deleted the
pointer will traverse to the end of the list.
Space Complexity
It requires only a fixed amount of extra space for the key variables. As a result, the
space complexity of the above algorithm is O(1). INPUT:
# include<stdio.h>
#
include<stdlib.h>
struct node { int
data ; struct node
*link ;
};
// Printing function void print(struct
node *ptr){ printf("The linked list is
: "); while (ptr!= NULL)
{ printf("%d ",ptr->data);
ptr=ptr->link;
} printf("\
n");
25
}
// Inserting at the starting of the linked list struct node*
insert_at_start(int data,struct node* head){ struct node
*start; start=(struct node *)malloc(sizeof(struct node));
start->data=data; start->link=head; head=start;
return head;
}
// Inserting at the end of the linked list struct node*
insert_at_end(int data,struct node* head){ struct node
*end,*ptr;
end=(struct node *)malloc(sizeof(struct node));
end->data=data; end->link=NULL; ptr=head;
while (ptr->link!= NULL){ ptr
= ptr->link;
} ptr-
>link=end;
return head;
}
// Inserting element at the user want position struct node*
insert_at_position(int data,int position,struct node* head){ int i ;
struct node *between,*ptr; between=(struct node
*)malloc(sizeof(struct node)); between->data=data; ptr=head;
for(i=1;i<(position1);i++){ ptr=ptr->link;
} between->link=ptr>link;
ptr-
>link=between; return
head;
}
int main(){ int
c,data,pos, choice;
struct node *head , *ptr; head = (struct node
*)malloc(sizeof(struct node)); printf("What value
you want to enter : ");
26
\n 2.Insert at between \
\n 3.Insert at the end\n");
Theory:
Step 6: Exit
Time Complexity –
To add a new node at the front, we are only updating a constant number of pointers, so the
time complexity is O(1).
Space Complexity –
To add a new node at the front, we only create the pointer to the new node. No additional
memory is needed, so the space complexity is O(1)
INPUT:
#include <stdio.h>
#include <stdlib.h> // Basic
structure of Node struct node
{ int data; struct node *
prev; struct node * next;
}*head, *last;
// Function used in this program
void createList(int n); void
displayListFromFirst(); void
displayListFromEnd(); int main()
{ int n,
choice;
28
head = NULL; last = NULL; printf("Enter the number of
nodes you want to create: "); scanf("%d", &n); createList(n);
// Create list of n nodes printf("\nPress 1 to display list from
First"); printf("\nPress 2 to display list from End : ");
scanf("%d", &choice); if(choice==1)
{
displayListFromFirst();
}
else if(choice == 2)
{ displayListFromEnd();
}
return 0;
}
/**
* Create a doubly linked list of n nodes.
* @n Number of nodes to be created
*/ void createList(int
n)
{ int i,
data;
struct node *newNode; if(n
>= 1)
{
head = (struct node *)malloc(sizeof(struct node));
if(head != NULL)
{
printf("Enter data of 1 node: ");
scanf("%d", &data); head->data =
data; head->prev = NULL;
head->next = NULL; last = head;
/*
// Create rest of the n-1 nodes
for(i=2; i<=n; i++)
{
newNode = (struct node *)malloc(sizeof(struct node));
if(newNode != NULL)
{
printf("Enter data of %d node: ", i);
scanf("%d", &data); newNode->data =
data;
29
newNode->prev = last; // Link new node with the previous node
newNode->next = NULL; last->next = newNode; // Link previous node
with the new node last = newNode; // Make new node as
last/previous node
}
else
{
printf("Unable to allocate memory.");
break;
}
}
printf("\nDOUBLY LINKED LIST CREATED SUCCESSFULLY\n"); }
else {
printf("Unable to allocate memory");
}
}
}
// Displays the content of the list from beginning to end void
displayListFromFirst()
{
struct node * temp;
int n = 1; if(head ==
NULL)
{
printf("List is empty.");
}
else
{
temp = head; printf("\n\nDATA IN THE LIST:\n");
while(temp != NULL) { printf("DATA of %d node =
%d\n", n, temp->data); n++;
//Move the current pointer to next node temp
= temp->next;
}
}
}
// Display the content of the list from last to first void
displayListFromEnd()
{
struct node * temp;
int n = 0; if(last ==
NULL)
{
printf("List is empty.");
30
}
else
{
temp = last; printf("\n\nDATA IN
THE LIST:\n"); while(temp !=
NULL)
{
printf("DATA of last-%d node = %d\n", n, temp->data); n++;
// Move the current pointer to previous node
temp = temp->prev;
}
}
}
OUTPUT:
31
INPUT:
#include <stdio.h>
#include <stdlib.h>
struct node { int num; struct node * preptr;
struct node * nextptr; }*stnode, *ennode; void
DlListcreation(int n); void
DlLinsertNodeAtBeginning(int num); void
displayDlList(int a);
int main() {
int n,num1,a; stnode =
NULL; ennode = NULL;
32
a=2; displayDlList(a); return
0;
}
void DlListcreation(int n)
{ int i, num; struct node
*fnNode;
if(n >= 1) {
33
}
}
}
void DlLinsertNodeAtBeginning(int num)
{
struct node * newnode; if(stnode == NULL)
{
printf(" No data found in the list!\n");
} else
{
newnode = (struct node *)malloc(sizeof(struct node)); newnode->num = num;
newnode->nextptr = stnode; // next address of new node is linking with starting node
newnode->preptr = NULL; // set previous address field of new node is NULL
stnode->preptr = newnode; // previous address of starting node is linking with new node
stnode = newnode; // set the new node as starting node } }
void displayDlList(int m)
{
struct node * tmp; int n = 1;
if(stnode == NULL)
{
printf(" No data found in the List yet.");
} else
{
tmp = stnode; if
(m==1) {
printf("\n Data entered in the list are :\n");
} else
{
printf("\n After insertion the new list are :\n");
}
while(tmp != NULL)
{
printf(" node %d : %d\n", n, tmp->num); n++;
tmp = tmp->nextptr; // current pointer moves to the next node }
}
34
}
OUTPUT:
35
Theory:
INPUT:
#include <stdio.h>
#include <stdlib.h>
struct node { int num; struct
node * preptr; struct node *
nextptr;
}*stnode, *ennode;
36
printf(" Input the position ( 1 to %d ) to delete a node : ",n); scanf("%d", &insPlc);
if(insPlc<1 || insPlc>n)
{
printf("\n Invalid position. Try again.\n ");
}
if(insPlc>=1 && insPlc<=n)
{
DlListDeleteAnyNode(insPlc); a=2;
displayDlList(a);
} return 0;
}
void DlListcreation(int n)
{
int i, num; struct node
*fnNode;
if(n >= 1)
{ stnode = (struct node *)malloc(sizeof(struct node));
stnode != NULL)
if( {
printf(" Input data for node 1 : "); // assigning data in the first node scanf("%d",
&num);
stnode->num = num;
stnode->preptr = NULL; stnode->nextptr
= NULL; ennode = stnode;
for(i=2; i<=n; i++)
{
fnNode = (struct node *)malloc(sizeof(struct node)); if(fnNode != NULL)
{
printf(" Input data for node %d : ", i); scanf("%d", &num);
fnNode->num = num;
fnNode->preptr = ennode;
// new node is linking with the previous node fnNode->nextptr = NULL;
// set next address of fnnode is NULL ennode->nextptr =
fnNode;
// previous node is linking with the new node
ennode = fnNode; // assign new node as last node
} else
{
printf(" Memory can not be allocated.");
37
break; printf(" Memory can not be
}
}e
} els
{
allocated.");
}
}
}
void DlListDeleteAnyNode(int pos)
{
struct node *curNode; int i;
curNode = stnode;
for(i=1; i<pos && curNode!=NULL; i++)
{
curNode = curNode->nextptr;
}
if(pos == {
}
else
{ if(
}
else
{ if(
1)
DlListDeleteFirstNode();
curNode == ennode)
DlListDeleteLastNode();
curNode != NULL)
}
else
{
}
free(curNode); //Delete the n node
38
stnode->preptr = NULL; // set previous address of staring node is NULL
free(NodeToDel); // delete the first node from memory
}
}
void DlListDeleteLastNode()
{
struct node * NodeToDel;
if(ennode == NULL)
{
printf(" Delete is not possible. No data in the list.\n");
} else
{
NodeToDel = ennode; ennode =
ennode->preptr;
// move the previous address of the last node to 2nd last node ennode->nextptr =
NULL; // set the next address of last node to NULL free(NodeToDel);
// delete the last node
}}
void displayDlList(int m)
{ struct node * tmp; int n
= 1; if(stnode == NULL)
{
printf(" No data found in the List yet.");
} else
{
tmp = stnode; if
(m==1) {
printf("\n Data entered in the list are :\n");
} else { printf("\n After deletion the new list are :\n");
} while(tmp != NULL)
{ printf(" node %d : %d\n", n, tmp->num); n++;
tmp = tmp->nextptr; // current pointer moves to the next node
}
}
}
39
OUTPUT:
40