Dsa Lab Program
Dsa Lab Program
I. To implement the
1 List ADT using
Arrays.
2 I. Stack ADT.
II. Queue ADT.
4 Write a program to
implement priority queue
ADT.
5 I. Insert an element
into a binary search tree
II. Delete an element
from a binary search tree.
8 I. Linear search.
9 I. Bubble sort.
Aim :
Algorithm :
Step 2 : Declare the functions create(), insert(), delete(), search() and display()
Step 3 : Call the declared functions using the switch – case statements.
Step 4 : Under the create() function, have to enter the number of nodes and the list of
elements to be added.
Step 5 : Under the delete() function, have to enter the position of the element to get
deleted. If the position is not available then have to display it is invalid position.
Step 6 : Under the search() function, have to search the element with its position.
Step 7 : Under the insert() function, have to insert the new element by comparing the
maximum size of the list.
Step 8 : Inside display() function, have to display the List after completing all the
operations.
#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;
int main()
{
//clrscr();
int ch;
char g='y';
do
{
printf("\n main Menu");
printf("\n [Link] \n [Link] \n [Link] \n [Link] \n [Link] \n");
printf("\n Enter your Choice");
scanf("%d", &ch);
switch(ch)
{
case 1:
create();
break;
case 2:
deletion();
break;
case 3:
search();
break;
case 4:
insert();
break;
case 5:
display();
break;
default:
printf("\n Enter the correct choice:");
}
printf("\n Do u want to continue:::");
scanf("\n%c", &g);
}
while(g=='y'||g=='Y');
getch();
}
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];
}
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("\n\n%d", b[i]);
}
}
Output:
main Menu
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Do u want to continue:::y
main Menu
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
4
Do u want to continue:::y
main Menu
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
main Menu
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
main Menu
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Enter your Choice4
Enter the position u need to insert::2
Enter the element to insert::
8
The list after insertion::
The Elements of The list ADT are:
8
8
6
Do u want to continue:::y
main Menu
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
Result :
Thus the above program for implementing the List ADT using arrays has been
executed successful
[Link] implement the List ADT using Linked Lists.
Aim :
Algorithm :
Step 2 : Define a Structure to declare the node and data to be inserted as Linked Lists
using struct keyword.
Step 3 : The functions create(), insert(), delete(), search() and display() are declared
using the defined structure.
Step 4 :Inside the create() function, have to create a new list by checking the size and t
the memory allocated using the sizeof operator.
Step 5 : The insert() function is used to insert the new node at the end of the list.
Step 6 : The display() function is used to display all the items in the list.
Step 7 : The freeList() function is used to free the occupied memory in the list.
Step 8 : Inside the main() function, all the declared functions has to be called by
#include <stdio.h>
#include <stdlib.h>
return poppedValue;
}
push(stack, 10);
push(stack, 20);
push(stack, 30);
display(stack);
return 0;
}
Output:
Result :
Thus the above program for implementing the List ADT using Linked Lists has been
executed successfully.
EX No: 2 Write a programs to implement the following using a singly linked list.
[Link] ADT.
Aim :
To write a C program to implement the Stack ADT using a Singly Linked List.
Algorithm :
Step 2 : Define a node and stack structure for the Linked list using the struct keyword.
Step 3 :Create a new node with the createNode() function by passing the data as an
argument.
Step 4 : Create a new empty stack by using the initializeStack() function and declare t
the stack value to NULL.
Step 5 : To check whether the stack is empty, declare the isEmpty() function and
return the NULL value if the stack is empty.
Step 6 : Insert the new element to the top of the Stack by using the push() function.
Step 7 : Delete an element from the non empty stack by using the pop() function and
return the deleted value.
Step 8 :The display() function is used to display the current elements of the stack.
Step 9 : Inside the main function, call all the declared functions by passing the
elements as an arguments.
#include <stdio.h>
#include <stdlib.h>
return poppedValue;
}
push(stack, 10);
push(stack, 20);
push(stack, 30);
display(stack);
return 0;
}
Output:
Result :
Thus the above program for implementing the Stack ADT using a Singly Linked List
has been executed successfully.
[Link] ADT.
Aim :
Algorithm :
Step 2 :Define a node and queue structure for the Linked list using the struct keyword.
Step 3 :Create a new node with the createNode() function by passing the data as an
argument.
Step 4 : Create a new empty queue by using the initializeQueue() function and declare
the queue value to NULL.
Step 5 : To check whether the queue is empty, declare the isEmpty() function and
return the NULL value if the queue is empty.
Step 6 :Insert the new element to the Queue by using the enqueue() function.
Step 7 :Delete an element from the non emptyqueue by using the dequeue() function
and return the deleted value.
Step 8 : The front and rear are the key pointers to add and delete an element from the
queue.
Step 9 :The display() function is used to display the current elements of the queue.
Step 10 :Inside the main function, call all the declared functions by passing the
elements as an arguments.
#include <stdio.h>
#include <stdlib.h>
// Define a Node structure for the linked list
struct Node {
int data;
struct Node* next;
};
if (isEmpty(queue)) {
queue->front = newNode;
queue->rear = newNode;
}
else
{
queue->rear->next = newNode;
queue->rear = newNode;
}
free(temp);
return dequeuedValue;
}
// Function to display the elements of the queue
void display(struct Queue* queue)
{
struct Node* current = queue->front;
printf("Queue: ");
while (current != NULL) {
printf("%d ", current->data);
current = current->next;
}
printf("\n");
}
// Main function to test the queue implementation
int main()
{
struct Queue* queue = initializeQueue();
enqueue(queue, 10);
enqueue(queue, 20);
enqueue(queue, 30);
display(queue);
Result :
Thus the above program for implementing the Queue ADT using a Singly Linked List
has been executed successfully.
Ex. No : 3 Write a program that reads an infix expression, converts the
expression to postfix form and then evaluates the postfix
expression (use stack ADT).
Aim :
To write a C program to read an infix expression and converts into postfix and
evaluate the postfix expression using Stack ADT.
Algorithm :
Step 2 : The push() and pop() functions are used to insert and delete an element from t
the Stack.
Step 3 : The priority() function is used to check the priority of the operator that which
operator has to be performed first.
Step 4 :Check the priority of the operators using the ‘if’ condition.
Step 5 : Inside the main function, get the values in the runtime.
Step 6 : Evaluate the expression according to its priority using the ‘while’ condition.
#include<stdio.h>
#include<ctype.h>
char stack[100];
int top = -1;
void push(char x)
{
stack[++top] = x;
}
char pop()
{
if(top == -1)
return -1;
else
return stack[top--];
}
int priority(char x)
{
if(x == '(')
return 0;
if(x == '+' || x == '-')
return 1;
if(x == '*' || x == '/')
return 2;
return 0;
}
int main()
{
char exp[100];
char *e, x;
while(*e != '\0')
{
if(isalnum(*e))
printf("%c ",*e);
else if(*e == '(')
push(*e);
else if(*e == ')')
{
while((x = pop()) != '(')
printf("%c ", x);
}
else
{
while(priority(stack[top]) >= priority(*e))
printf("%c ",pop());
push(*e);
}
e++;
}
while(top != -1)
{
printf("%c ",pop());
}return 0;
}
Output:
ab+c*da-+
--------------------------------
Process exited after 34.57 seconds with return value 0
Press any key to continue . . .
Result :
Thus the above program for converting an infix expression to postfix expression and
its evaluation using Stack ADT has been executed successfully.
Ex. No : 4 Write a program to implement priority queue ADT.
Aim :
To write a C program to implement the queue operations using the Priority Queue
ADT.
Algorithm :
Step 2 : Declare insert_by_priority() function to insert the elements into the Queue.
Step 5 : The check() function is used to check the priority and place the element to be
inserted.
Step 6 : The display() function is used to display all the elements in the queue.
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
void insert_by_priority(int);
void delete_by_priority(int);
void create();
void check(int);
void display_pqueue();
int pri_que[MAX];
int front, rear;
void main()
{
int n, ch;
printf("\n1 - Insert an element into queue");
printf("\n2 - Delete an element from queue");
printf("\n3 - Display queue elements");
printf("\n4 - Exit");
create();
while (1)
{
printf("\nEnter your choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("\nEnter value to be inserted : ");
scanf("%d",&n);
insert_by_priority(n);
break;
case 2:
printf("\nEnter value to delete : ");
scanf("%d",&n);
delete_by_priority(n);
break;
case 3:
display_pqueue();
break;
case 4:
exit(0);
default:
printf("\nChoice is incorrect, Enter a correct choice");
}
}
}
/* Function to create an empty priority queue */
void create()
{
front = rear = -1;
}
pri_que[i] = -99;
rear--;
if (rear == -1)
front = -1;
return;
}
}
printf("\n%d not found in queue to delete", data);
}
front = 0;
}
Output:
Result :
Thus the above program to implement the queue operations using the Priority Queue
ADT has been executed successfully.
Ex. No : 5 Write a program to perform the following operations.
Aim :
Algorithm :
Step 3 : The inorder() function is used to traverse in the Binary search tree along with
their nodes.
Step 4 : The insert() function is used to insert the new element to the tree by checking
whether the tree is empty or not.
Step 5 : If the tree is empty, create the new tree otherwise add the elements to the tree
as its child nodes.
Step 6 : Inside the main() function, call the function along with its parameters.
#include<stdio.h>
#include<stdlib.h>
struct node {
int key;
struct node *left, *right;
};
return 0;
}
Output:
20 30 40 50 60 70 80
--------------------------------
Process exited after 0.03565 seconds with return value 0
Press any key to continue . . .
Result :
Thus the above program to insert an element into the Binary Search tree has been
executed successfully.
[Link] an element from a binary search tree.
Aim :
Algorithm :
Step 3 :The inorder() function is used to traverse in the Binary search tree along with
their nodes.
Step 4 :The insert() function is used to insert the new element to the tree by checking
whether the tree is empty or not.
Step 5 :If the tree is empty, create the new tree otherwise add the elements to the tree
as its child nodes.
Step 6 : The deleteNode() is used to delete the particular node from the
Step 7 : The deleteNode() function has to be called recursively for deleting both the le
left and right nodes of the tree.
Step 8 : If both the left and right childs are empty, then return the root value.
Step 9 : Inside the main function, call all the functions along with its parameters.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int key;
struct Node *left, *right;
};
{
struct Node* succParent = root;
// Find successor
struct Node* succ = root->right;
while (succ->left != NULL)
{
succParent = succ;
succ = succ->left;
}
// Driver Code
int main()
{
return 0;
}
Output:
Original BST: 20 30 40 50 60 70
30 40 50 60
Result :
Thus the above program for deleting an element from the Binary search tree has been
executed successfully.
III. Search for a key element in a binary search tree.
Aim :
Algorithm :
Step 2 : Create a Binary Tree by declaring the TreeNode structure to declare both the r
root node and the child node.
Step 3 :The insertNode() function is used to insert the new elements to be added to the
Binary Search tree.
Step 4 :Initialise the root node value to NULL and add the elements to the tree by
using the ‘if’ condition.
Step 5 : The searchNode() function is used to search the particular element in the tree.
Step 6 : Inside the main function, get the choice has to be made in the runtime and
insertion and searching of elements functions can be performed using the
switch-case statements.
struct TreeNode {
int data;
struct TreeNode *leftChildNode;
struct TreeNode *rightChildNode;
};
typedef struct TreeNode node;
node *rootNode = NULL;
/* Function to insert a node in a Binary search tree */
void insertNode(int i, node **n) {
if (*n == NULL) {
(*n) = (node*)malloc(sizeof(node));
(*n)->leftChildNode = NULL;
(*n)->rightChildNode = NULL;
(*n)->data = i;
}
else if ((*n)->data == i)
printf("\nThis value already exists in the tree!");
else if (i > (*n)->data)
insertNode(i, &((*n)->rightChildNode));
else
insertNode(i, &((*n)->leftChildNode));
}
/* End of insertNode() */
/* End of serachNode() */
/* The main() program begins */
int main()
{
int ch, num, num1;
do {
printf("\nSelect a choice from the menu below.");
printf("\n1. Insert a node.");
printf("\n2. Search for a node.");
printf("\nChoice: ");
scanf("%d", &ch);
switch(ch) {
case 1:
printf("\nEnter an element: ");
scanf("%d", &num);
insertNode(num, &rootNode);
break;
case 2:
printf("\nEnter the element to be searched for: ");
scanf("%d", &num);
searchNode(num, &rootNode);
break;
default:
exit(0);
}
printf("\nIf you want to return to the menu, press 1.");
printf("\nChoice: ");
scanf("%d", &num);
} while(num == 1);
return 0;
}
Output:
Enter an element: 45
Enter an element: 24
Enter an element: 85
Value found!
If you want to return to the menu, press 1.
Choice:
Result :
Thus the above program to search for an element in a Binary search tree has been
excuted successfully.
Ex. No : 6 Write a program to perform the following operations.
Aim :
Algorithm :
Step 3 : The height() function is used to get the height of the tree.
Step 4 : The max() function is used to get the maximum of two integers.
Step 5 : The newNode() function is used to allocate a new node with its left and right
pointers.
Step 6 : The rightRotate() and leftRotate() is used to rotate the tree and update the
height of the tree.
#include<stdio.h>
#include<stdlib.h>
/* Helper function that allocates a new node with the given key and
NULL left and right pointers. */
struct Node* newNode(int key)
{
struct Node* node = (struct Node*)
malloc(sizeof(struct Node));
node->key = key;
node->left = NULL;
node->right = NULL;
node->height = 1; // new node is initially added at leaf
return(node);
}
// Perform rotation
x->right = y;
y->left = T2;
// Update heights
y->height = max(height(y->left),
height(y->right)) + 1;
x->height = max(height(x->left),
height(x->right)) + 1;
// Perform rotation
y->left = x;
x->right = T2;
// Update heights
x->height = max(height(x->left),
height(x->right)) + 1;
y->height = max(height(y->left),
height(y->right)) + 1;
{
if (N == NULL)
return 0;
return height(N->left) - height(N->right);
}
return 0;
}
Output:
Result :
Thus the above program to insert an element into an AVL tree has been executed
successfully.
[Link] from an AVL-tree.
Aim :
Algorithm :
Step 3 :The height() function is used to get the height of the tree.
Step 4 :The max() function is used to get the maximum of two integers.
Step 5 :The newNode() function is used to allocate a new node with its left and right
pointers.
Step 6 :The rightRotate() and leftRotate() is used to rotate the tree and update the
height of the tree.
Step 9 : Check whether the nodes of the tree is balanced, using the getBalance()
function.
Step 10 : Inside the main() function, call all the values with its parameters.
#include<stdio.h>
#include<stdlib.h>
/* Helper function that allocates a new node with the given key and
NULL left and right pointers. */
struct Node* newNode(int key)
{
struct Node* node = (struct Node*)
malloc(sizeof(struct Node));
node->key = key;
node->left = NULL;
node->right = NULL;
node->height = 1; // new node is initially added at leaf
return(node);
}
// Update heights
y->height = max(height(y->left), height(y->right))+1;
x->height = max(height(x->left), height(x->right))+1;
// Perform rotation
y->left = x;
x->right = T2;
// Update heights
x->height = max(height(x->left), height(x->right))+1;
y->height = max(height(y->left), height(y->right))+1;
return current;
}
if (root == NULL)
return root;
// No child case
if (temp == NULL)
{
temp = root;
root = NULL;
}
else // One child case
*root = *temp; // Copy the contents of
// the non-empty child
free(temp);
}
Else
{
// node with two children: Get the inorder
// successor (smallest in the right subtree)
struct Node* temp = minValueNode(root->right);
}
return root;
}
Result :
Thus the above program for delete an element from the AVL tree has been executed
successful
Ex. No : 7 Write a programs for the implementation of BFS and DFS for a given
graph.
Aim :
To write a C program to implement the BFS and DFS for the graph.
Algorithm :
Step 2 : Declare the functions like add(), bfs(), dfs(),push() and pop() to perform the
operations.
Step 3 : The bfs() function starts from the top node in the graph and travels down until
it reaches the root node.
Step 4 : The dfs() function starts from the top node and follows a path to reaches the e
end node of the path.
#include<stdio.h>
int q[20],top=-1,front=-1,rear=-1,a[20][20],vis[20],stack[20];
int delete();
void add(int item);
void bfs(int s,int n);
void dfs(int s,int n);
void push(int item);
int pop();
void main()
{
int n,i,s,ch,j;
char c,dummy;
printf("ENTER THE NUMBER VERTICES ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("ENTER 1 IF %d HAS A NODE WITH %d ELSE 0 ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("THE ADJACENCY MATRIX IS\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf(" %d",a[i][j]);
}
printf("\n");
}
do
{
for(i=1;i<=n;i++)
vis[i]=0;
printf("\nMENU");
printf("\n1.B.F.S");
printf("\n2.D.F.S");
printf("\nENTER YOUR CHOICE");
scanf("%d",&ch);
printf("ENTER THE SOURCE VERTEX :");
scanf("%d",&s);
switch(ch)
{
case 1:bfs(s,n);
break;
case 2:
dfs(s,n);
break;
}
printf("DO U WANT TO CONTINUE(Y/N) ? ");
scanf("%c",&dummy);
scanf("%c",&c);
}while((c=='y')||(c=='Y'));
}
//**************BFS(breadth-first search) code**************//
void bfs(int s,int n)
{
int p,i;
add(s);
vis[s]=1;
p=delete();
if(p!=0)
printf(" %d",p);
while(p!=0)
{
for(i=1;i<=n;i++)
if((a[p][i]!=0)&&(vis[i]==0))
{
add(i);
vis[i]=1;
}
p=delete();
if(p!=0)
printf(" %d ",p);
}
for(i=1;i<=n;i++)
if(vis[i]==0)
bfs(i,n);
}
void add(int item)
{
if(rear==19)
printf("QUEUE FULL");
else
{
if(rear==-1)
{
q[++rear]=item;
front++;
}
else
q[++rear]=item;
}
}
int delete()
{
int k;
if((front>rear)||(front==-1))
return(0);
else
{
k=q[front++];
return(k);
}
}
//***************DFS(depth-first search) code******************//
void dfs(int s,int n)
{
int i,k;
push(s);
vis[s]=1;
k=pop();
if(k!=0)
printf(" %d ",k);
while(k!=0)
{
for(i=1;i<=n;i++)
if((a[k][i]!=0)&&(vis[i]==0))
{
push(i);
vis[i]=1;
}
k=pop();
if(k!=0)
printf(" %d ",k);
}
for(i=1;i<=n;i++)
if(vis[i]==0)
dfs(i,n);
}
void push(int item)
{
if(top==19)
printf("Stack overflow ");
else
stack[++top]=item;
}
int pop()
{
int k;
if(top==-1)
return(0);
else
{
k=stack[top--];
return(k);
}
}
Output:
MENU
1.B.F.S
2.D.F.S
ENTER YOUR CHOICE1
ENTER THE SOURCE VERTEX :2
2 1 3 DO U WANT TO CONTINUE(Y/N) ? y
MENU
1.B.F.S
2.D.F.S
ENTER YOUR CHOICE2
ENTER THE SOURCE VERTEX :2
2 3 1 DO U WANT TO CONTINUE(Y/N) ?
Result :
Thus the above program for the implementation of BFS and DFS for the given graph
has been executed successfully.
Ex. No : 8 Write a programs for implementing the following searching methods.
[Link] search.
Aim :
Algorithm :
Step 2 : Linear search is the approach to search for an element in a data set.
Step 6 : Find the element using the index position by checking using if condition.
#include<stdio.h>
int main()
{
int a[20],i,x,n;
printf("How many elements?");
scanf("%d",&n);
for(i=0;i<n;++i)
if(a[i]==x)
break;
if(i<n)
printf("Element found at index %d",i);
else
printf("Element not found");
return 0;
}
Output:
Result :
Thus the above program for search the element using linear search approach has been
executed successfully.
[Link] search.
Aim :
Algorithm :
Step 2 : Binary Search finds the position of a target value within a sorted array.
Step 6 : Find the element using the mid value and key value.
#include <stdio.h>
int main()
{
int i, low, high, mid, n, key, array[100];
printf("Enter number of elements\n");
scanf("%d",&n);
printf("Enter %d integer\n", n);
for(i = 0; i < n; i++)
scanf("%d",&array[i]);
printf("Enter value to find\n");
scanf("%d", &key);
low = 0;
high = n - 1;
mid = (low+high)/2;
while (low <= high) {
if(array[mid] < key)
low = mid + 1;
else if (array[mid] == key) {
printf("%d found at location %d\n", key, mid+1);
break;
}
else
high = mid - 1;
mid = (low + high)/2;
}
if(low > high)
printf("Not found! %d isn't present in the list\n", key);
return 0;
}
Output:
Result :
Thus the above program for search the element using binary search approach has been
executed successfully.
Ex. No : 9 Write a programs for implementing the following sorting methods.
[Link] sort.
Aim :
Algorithm :
Step 4 : Bubble sort involves comparing and swapping two adjacent elements.
Step 5 : Using ‘for’ loop and ‘if’ loop, compare the numbers and arrange the numbers
in the correct order.
#include <stdio.h>
int main(){
int arr[50], num, x, y, temp;
printf("Please Enter the Number of Elements you want in the array: ");
scanf("%d", &num);
printf("Please Enter the Value of Elements: ");
for(x = 0; x < num; x++)
scanf("%d", &arr[x]);
for(x = 0; x < num - 1; x++){
for(y = 0; y < num - x - 1; y++){
if(arr[y] > arr[y + 1]){
temp = arr[y];
arr[y] = arr[y + 1];
arr[y + 1] = temp;
}
}
}
printf("Array after implementing bubble sort: ");
for(x = 0; x < num; x++){
printf("%d ", arr[x]);
}
return 0;
}
Output:
Result :
Thus the above program for implementing bubble sort has been executed successfully
II. Selection sort.
Aim :
Algorithm :
Step 4 : Selection sort involves finding the smallest element in the list and swapping it
with the first element in the unsorted portion of the list.
Step 5 : Using ‘for’ loop and ‘if’ loop, compare the numbers and arrange the numbers
in the correct order.
#include <stdio.h>
int main()
{
int array[100], n, c, d, position, t;
return 0;
}
Output:
--------------------------------
Process exited after 22.11 seconds with return value 0
Press any key to continue .
Result :
Thus the above program for implementing selection sort has been executed
successfully.
[Link] sort.
Aim :
Algorithm :
Step 4 : Insertion sort builds the final sorted list one item at a time by comparisons.
Step 5 : Using ‘for’ loop and ‘if’ loop, compare the numbers and arrange the numbers
in an ascending order.
#include <stdio.h>
int main()
{
int n, array[1000], c, d, t, flag = 0;
return 0;
}
Output:
--------------------------------
Process exited after 14.83 seconds with return value 0
Press any key to continue . . .
Result :
Thus the above program for implementing insertion sort has been executed
successfully.
[Link] sort.
Aim :
Algorithm :
Step 2 : Radix sort that sorts data with integer keys by grouping the keys by individual
digits that share the significant position and value.
Step 3 : Inside the RadixSort() function, have to print the largest element and also to
display the elements both in ascending and descending order.
Step 5 : The RadixSort() function along with its parameters have to be called inside
the main() function.
#include<stdio.h>
i = 0;
for(k = 0; k < 10; k++)
{
for(j = 0; j < bucket_count[k]; j++)
{
a[i] = bucket[k][j];
i++;
}
}
divisor *= 10;
--------------------------------
Process exited after 36.19 seconds with return value 0
Press any key to continue . . .
Result :
Thus the above program for implementing radix sort has been executed successfully.