Datastructure Completed
Datastructure Completed
TABLE OF CONTENTS
Experiments Page No
1. Sort a given list of strings - 3
2. Reverse a string using pointers - 5
3. Pattern matching - 7
4. 2-D Array search - 9
5. Append 2 arrays - 12
6. Linear search - 16
7. Binary search - 19
8. Sparse metrix&Triplet representation - 22
9. Linked list- Display - 25
10. Linked list - Deletion - 29
11. Linked list - Sort - 35
12. Linked list - Search - 40
13. Doubly linked list- bckwrd,frwrd repn - 45
14. Addition of 2 polynomials using array - 49
15. Implement Stack using array - 54
16. Implement Stack using linked list - 60
17. Evaluation of postfix expression - 65
18. Implement Queue using array - 68
19. Implement Queue using linked list - 72
20. Traverse a binary search tree in preorder - 77
21. Traverse a binary search tree in inorder - 81
22. Traverse a binary search tree in postorder - 84
23. Search an element in a binary search tree - 87
24. Implement exchange sort - 91
25. Implement selection sort - 94
26. Implement insertion sort - 97
27. Implement quick sort - 100
PAGE NO:3
set strcpy(temp,str[i]);
set strcpy(str[i],str[j]);
set strcpy(str[j],temp);
step 8: j++
step 9: i++
step 10: write sorted array str
step 11:stop
C CODE:
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,count;
char str[25][25],temp[25];
clrscr();
puts("How many strings u are going to enter?: ");
scanf("%d",&count);
puts("Enter Strings one by one: ");
for(i=0;i<=count;i++) PAGE NO:4
gets(str[i]);
for(i=0;i<=count;i++)
for(j=i+1;j<=count;j++)
{
if(strcmp(str[i],str[j])>0)
{
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
getch();
return 0;
}
OUTPUT
PAGE NO:5
ALGORITHM:
step 1:start
step 2:declare variables len,i of integer and character pointer s
step 3:read s
step 4:store string length to len
step 5: set i=len, for i>=0 repeat
print *(s+i)
step 6:i--
step 7:stop
C CODE:
#include <stdio.h>
#include <conio.h>
void main()
{
char *s;
int len,i;
clrscr();
printf("\nENTER A STRING: ");
gets(s);
len=strlen(s);
printf("\nTHE REVERSE OF THE STRING IS:");
for(i=len;i>=0;i--)
printf("%c",*(s+i));
getch();
}
PAGE NO:6
OUTPUT:
PAGE NO:7
ALGORITHM:
step 1:start
step 2:declare variables m,n,i,j of integers and character array
str1,str2
step 3:read string in str1 and pattern in str2
step 4:set m=strlen(str1) and n=strlen(str2)
step 5: set i=0, repeat step 6 to 9 until i<m-n+1
step 6: set j=0 repeat step 7 to 8 until j<n
step 7: if(str1[i+j] != str2[j])
break;
if(j == n)
print pattern found at i+1
step 8: j++
step 9:i++
step 10: stop
C CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[20],str2[20];
int m,n,i,j;
clrscr();
printf("\nEnter text string : ");
gets(str1);
PAGE NO:8
m = strlen(str1);
n = strlen(str2);
for(i=0;i<m-n+1;i++)
{
for(j=0;j<n;j++)
{
if(str1[i+j] != str2[j])
break;
}
if(j == n)
{
printf("\n\n Pattern found at %d. ",i+1);
}
}
getch();
}
OUTPUT:
PAGE NO:9
step 1:start
step 2: declare i,j,r,c,item,loc,loc1 and a[][] array
step 3: read number of rows,r and columns,c
step 4:set i=1, repeat step 5 to 8 until i<=r
step 5: set j=1, repeat step 6 to 7 until j<=C
step 6: read a[i][j]
step 7:j++
step 8:i++
step 9:read search element as item
step 10:set i=1, repeat step 11 to 14 until i<=r
step 11: set j=1, repeat step 12 to 13 until j<=c
step 12:
if item = a[i][j]
set loc=i;
set loc1=j;
set break;
step 13: j++
PAGE NO:10
step 14:i++
step 15:print loc & loc1
step 16:stop
C CODE:
void main()
{
int i=0,j=0,r=0,c=0,item,loc=0,loc1=0;
int a[10][10];
clrscr();
printf("\n\tThis Program is Used To search an element in
2Dimensional Array using Linear Search\n");
printf("\nEnter the number of rows&columns:\n");
scanf("\n%d\n%d",&r,&c);
printf("\n\tEnter The %dx%d Array:\n",r,c);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
scanf("%d",&a[i][j]);
}
printf("\n\tEneter The Value To Be Serched:");
scanf("%d",&item);
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
if(item==a[i][j])
{
PAGE NO:11
loc=i;
loc1=j;
break;
}
}
}
printf("\n\tThe Item is at %d Row And %d
Coloumn.",loc,loc1);
printf("\n\n\t\tSearch Completed.");
getch();
}
OUTPUT:
PAGE NO:12
5.Append 2 arrays
ALGORITHM:
step 1: start
step 2: declare variables i,j,k,n1,n2 and arr1[],arr2[],re[] of
integer
step 3: read no.of elements as n1,n2 store elements in
arr1[],arr2[]
step 4: set i=0,j=0,k=0
step 5: repeat step 6 while i< n1 && j < n2
step 6:
if arr1[i] <= arr2[j]
set res[k] = arr1[i]
set i++;
set k++;
else
set res[k] = arr2[j]
set k++
set j++
step 7:
while i < n1
set res[k] = arr1[i]
set i++
PAGE NO:13
set k++
step 8:
while j < n2
set res[k] = arr2[j]
set k++
set j++
C CODE:
#include<stdio.h>
int main()
{
int arr1[30], arr2[30], res[60];
int i, j, k, n1, n2;
i = 0;
j = 0;
k = 0;
// Merging starts
while (i < n1 && j < n2)
{
if (arr1[i] <= arr2[j])
{
res[k] = arr1[i];
i++;
k++;
}
else
{
res[k] = arr2[j];
k++;
j++;
}
}
/* Some elements in array 'arr1' are still remaining
where as the array 'arr2' is exhausted */
return (0);
}
OUT PUT:
PAGE NO:16
ALGORITHM:
step 1: start
step 2: declare variables search,c,n & array of integers
step 3:read n as number of elements in array
step 4:set c=0, read array[c] until c<n
step 5:read search number as search
step 6: set c=0, repeat step 7 to step 8 until c<n
step 7:
if (array[c] == search)
write "present" search,c+1
step 8:c++
step 9:
if (c == n)
write "not present",search
step 10:stop
PAGE NO:17
C CODE:
#include <stdio.h>
int main()
{
int array[100], search, c, n;
clrscr();
printf("Enter number of elements in array\n");
scanf("%d", &n);
getch();
return 0;
}
PAGE NO:18
OUTPUT:
PAGE NO:19
step 1: start
step 2: declare variables c,first,last,middle,n,search & array[] of integer
step 3: read total elements as n and store to array[]
step 4: read search item as search
step 5: set
first = 0;
last = n - 1;
middle = (first+last)/2;
step 8:
if first>last
write "not found"
PAGE NO:20
step 9: stop
C CODE:
#include <stdio.h>
int main()
{
int c, first, last, middle, n, search, array[100];
clrscr();
printf("Enter number of elements\n");
scanf("%d", &n);
first = 0;
last = n - 1;
middle = (first+last)/2;
OUTPUT:
PAGE NO:22
#include <stdio.h>
#define MAX 20
int main()
{
int a[10][10], b[MAX][3], row, column;
clrscr();
printf("\nEnter the size of matrix (rows, columns): ");
scanf("%d%d", &row, &column);
OUTPUT:
PAGE NO:25
C CODE:
#include <stdio.h>
#include <stdlib.h>
struct node
{
int num; //Data of the node
struct node *nextptr; //Address of the next node
}*stnode;
int main()
{
int n;
clrscr();
printf("\n\n Linked List : To create and display Singly
Linked List :\n");
printf("---------------------------------------------------------\n");
void displayList()
{
struct node *tmp;
if(stnode == NULL)
{
printf(" List is empty.");
}
else
{
tmp = stnode;
while(tmp != NULL)
{ // prints the data of
PAGE NO:28
printf(" Data = %d\n", tmp->num); //current node
tmp = tmp->nextptr; // advances the position
//of current node
}
}
}
OUTPUT:
PAGE NO:29
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data; // Data
struct node *next; // Address
} * head;
int main()
{
int n, key;
clrscr();
// Input node count to create
printf("Enter number of node to create: ");
scanf("%d", &n);
createList(n);
// Display list
printf("\nData in list before deletion\n");
displayList();
PAGE NO:30
printf("\nEnter element to delete with key: ");
scanf("%d", &key);
void createList(int n)
{
struct node *newNode, *temp;
int data, i;
head = malloc(sizeof(struct node));
if (head == NULL)
{
printf("Unable to allocate memory. Exiting from app.");
exit(0);
}
if (newNode == NULL)
{
printf("Unable to allocate memory. Exiting from
app.");
exit(0);
}
void displayList()
{
PAGE NO:32
struct node *temp;
/*
* If the list is empty i.e. head = NULL,
* dont perform any action and return.
*/
if (head == NULL)
{
printf("List is empty.\n");
return;
}
temp = head;
while (temp != NULL)
{
printf("%d, ", temp->data);
temp = temp->next; // Move to next node
}
printf("\n");
}
prev = NULL;
cur = head;
free(cur);
return;
}
prev = cur;
PAGE NO:34
cur = cur->next;
}
}
OUTPUT:
PAGE NO:35
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data; // Data
struct node *next; // Address
} * head;
int main()
{
int n, key;
clrscr();
printf("Enter number of node to create: ");
scanf("%d", &n);
createList(n);
void createList(int n)
{
struct node *newNode, *temp;
int data, i;
if (head == NULL)
{
printf("Unable to allocate memory. Exiting from
app.");
exit(0);
}
void displayList()
{
struct node *temp;
if (head == NULL) PAGE NO:38
{
printf("List is empty.\n");
return;
}
temp = head;
while (temp != NULL)
{
printf("%d, ", temp->data);
temp = temp->next; // Move to next node
}
printf("\n");
}
void sortList()
{
struct node *first,*second;
int temp_data;
first=head;
printf("THE LIST AFTER SORTING IS:");
while(first!=NULL)
{
second=first->next;
while(second!=NULL)
{
if(first->data>second->data)
{ PAGE NO:39
temp_data=first->data;
first->data=second->data;
second->data=temp_data;
}
second=second->next;
}
first=first->next;
}
}
OUTPUT:
PAGE NO:40
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data; // Data
struct node *next; // Address
} * head;
int main()
{
int n, keyToSearch, index;
clrscr();
printf("Enter number of node to create: ");
scanf("%d", &n);
createList(n);
index = search(keyToSearch);
getch();
return 0;
}
void createList(int n)
{
struct node *newNode, *temp;
int data, i;
if (head == NULL)
{
printf("Unable to allocate memory. Exiting from app.");
exit(0);
}
void displayList()
{
struct node *temp;
if (head == NULL)
{
printf("List is empty.\n");
return;
}
temp = head;
while (temp != NULL)
{
printf("%d, ", temp->data);
temp = temp->next; // Move to next node
}
printf("\n");
}
/**
* Search an element with given key in linked list.
* It return a positive integer specifying index of the element
* on success, otherwise returns -1.
*/
int search(int key)
{
int index;
PAGE NO:44
struct node *curNode;
index = 0;
curNode = head;
OUTPUT:
PAGE NO:45
C CODE:
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *prev;
struct node *next;
};
printf("\nLIST:");
//start from the beginning
while(ptr != NULL)
{
PAGE NO:46
printf(" \t%d ",ptr->data);
ptr = ptr->next;
}
printf("\nLIST IN BACKWARD:");
//start from the beginning
while(ptr != NULL)
{
printf("\t%d",ptr->data);
ptr = ptr->prev;
}
link->data = data;
link->prev = NULL;
PAGE NO:47
link->next = NULL;
current = head;
int main()
{
int data,i=0,n;
clrscr();
for(i=0;i<+n;i++)
{
PAGE NO:48
scanf("%d",&data);
insert(data);
}
printList();
print_backward();
getch();
return 0;
}
OUTPUT:
PAGE NO:49
C CODE:
#include<stdio.h>
#include<conio.h>
main()
{
int a[10], b[10], c[10],m,n,k,k1,i,j,x;
clrscr();
printf("\tPolynomial Addition\n");
printf("\n\tEnter the no. of terms of the polynomial:");
scanf("\t%d", &m);
if(a[k1+1]==1)
printf("x^%d", a[k1]);
else
printf("%dx^%d", a[k1+1],a[k1]);
k1+=2;
while (k1<i)
PAGE NO:50
{
printf("+%dx^%d", a[k1+1],a[k1]);
k1+=2;
}
for(j=0;j<2*n;j++)
scanf("\t%d", &b[j]);
if(b[k1+1]==1)
printf("x^%d", b[k1]);
else
printf("%dx^%d",b[k1+1],b[k1]);
k1+=2;
while (k1<2*n)
{
printf("+%dx^%d", b[k1+1],b[k1]);
k1+=2;
}
i=0;
j=0;
k=0;
while (m>0)
{
c[k+1]=a[i+1];
c[k]=a[i];
PAGE NO:52
k+=2;
i+=2;
m--;
}
while (n>0)
{
c[k+1]=b[j+1];
c[k]=b[j];
k+=2;
j+=2;
n--;
}
while (k1<k)
{
if (c[k1+1]==1)
printf("+x^%d", c[k1]);
else
printf("+%dx^%d", c[k1+1], c[k1]);
k1+=2;
}
PAGE NO:53
getch();
return 0;
}
OUTPUT:
(different degrees)
(same degrees)
PAGE NO:54
C CODE:
#include<stdio.h>
int stack[100],choice,n,top,x,i;
void push(void);
void pop(void);
void display(void);
int main()
{
clrscr();
top=-1;
printf("\n Enter the size of STACK[ MAX=100 ]:");
scanf("%d",&n);
printf("\n\t STACK OPERATIONS USING ARRAY");
printf("\n\t--------------------------------");
printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.DISPLAY STACK
ELEMNTS \n\t 4.EXIT");
do
{
printf("\n Enter the Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
push();
break;
case 2:
PAGE NO:55
pop();
break;
case 3:
display();
break;
case 4:
printf("\n\t EXIT POINT ");
break;
default:
printf ("\n\t Please Enter a Valid
Choice(1/2/3/4)");
}
} while(choice!=4);
return 0;
}
void push()
{
if(top>=n-1)
printf("\n\tSTACK is over flow");
else
{
printf(" Enter a value to be pushed:");
scanf("%d",&x);
top++;
stack[top]=x;
}
PAGE NO:56
}
void pop()
{
if(top<=-1)
printf("\n\t Stack is under flow");
else
{
printf("\n\t The popped elements is %d",stack[top]);
top--;
}
}
void display()
{
if(top>=0)
{
printf("\n The elements in STACK \n");
for(i=top; i>=0; i--)
printf("\n%d",stack[i]);
printf("\n Press Next Choice");
}
else
{
printf("\n The STACK is empty");
}
}
PAGE NO:57
OUTPUT:
PAGE NO.58
PAGE NO. 59
PAGE NO.60
#include<stdio.h>
#include<conio.h>
struct Node
{
int data;
struct Node *next;
}*top = NULL;
void push(int);
void pop();
void display();
int main()
{
int choice, value;
clrscr();
printf("\n:: Stack using Linked List ::\n");
void pop()
{
if(top == NULL)
printf("\nStack is Empty!!!\n");
else
{
struct Node *temp = top;
printf("\nDeleted element: %d", temp->data);
top = temp->next;
free(temp);
}
}
void display()
{
if(top == NULL)
printf("\nStack is Empty!!!\n");
else
{
struct Node *temp = top;
while(temp->next != NULL)
{
printf ("%d--->",temp->data);
temp = temp -> next;
}
printf("%d--->NULL",temp->data);
}
}
PAGE NO.63
OUTPUT:
PAGE NO. 64
PAGE NO. 65
#include<stdio.h>
int stack[20];
int top = -1;
void push(int x)
{
stack[++top] = x;
}
int pop()
{
return stack[top--];
}
int main()
{
char exp[20];
char *e;
int n1,n2,n3,num;
clrscr();
printf("Enter The Expression :: ");
scanf("%s",exp);
e = exp;
while(*e != '\0')
{
if(isdigit(*e))
PAGE NO. 66
{
num = *e - 48;
push(num);
}
else
{
n1 = pop();
n2 = pop();
switch(*e)
{
case '+':
n3 = n1 + n2;
break;
case '-':
n3 = n2 - n1;
break;
case '*':
n3 = n1 * n2;
break;
case '/':
n3 = n2 / n1;
break;
}
push(n3);
}
e++;
}
printf("\nThe result of expression %s = %d\n\n",exp,pop());
getch();
PAGE NO. 67
return 0;
}
OUTPUT:
PAGE NO. 68
#include<stdio.h>
#include<conio.h>
#define n 5
void main()
{
int queue[n],ch=1,front=0,rear=0,i,j=1,x=n;
clrscr();
printf("\n\tQueue using Array");
printf("\n\t1.Insertion \n\t2.Deletion \n\t3.Display
\n\t4.Exit");
while(ch)
{
printf("\nEnter the Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(rear==x)
printf("\n Queue is Full");
else
{
printf("\n Enter no %d:",j++);
scanf("%d",&queue[rear++]);
}
break;
case 2:
if(front==rear)
PAGE NO. 69
{
printf("\n Queue is empty");
}
else
{
printf("\n Deleted Element is
%d",queue[front++]);
x++;
}
break;
case 3:
printf("\n Queue Elements are:\n ");
if(front==rear)
printf("\n Queue is Empty");
else
for(i=front; i<rear; i++)
{
printf("%d",queue[i]);
printf("\n");
}
break;
case 4:
exit(0);
default:
printf("Wrong Choice: please see the
options");
}
}
getch();
}
PAGE NO. 70
OUTPUT:
PAGE NO. 71
PAGE NO. 72
C CODE:
#include<stdio.h>
#include<conio.h>
struct Node
{
int data;
struct Node *next;
}*front = NULL,*rear = NULL;
void insert(int);
void delete();
void display();
void main()
{
int choice, value;
clrscr();
printf("\n:: Queue Implementation using Linked List ::\n");
do
{
switch(choice)
{
case 1: printf("Enter the value to be insert: ");
scanf("%d", &value);
insert(value);
break;
case 2: delete();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("\nWrong selection!!! Please try
again!!!\n");
}
} while(choice!=4);
}
void delete()
{
if(front == NULL)
printf("\nQueue is Empty!!!\n");
else
{
struct Node *temp = front;
front = front -> next;
printf("\nDeleted element: %d\n", temp->data);
free(temp);
}
}
void display()
{
if(front == NULL)
printf("\nQueue is Empty!!!\n");
else
{
struct Node *temp = front;
while(temp->next != NULL)
{
printf("%d--->",temp->data);
temp = temp -> next;
PAGE NO. 75
}
printf("%d--->NULL\n",temp->data);
}
}
OUTPUT:
PAGE NO. 76
PAGE NO. 77
C CODE:
#include<stdio.h>
#include<conio.h>
node *create()
{
node *p;
int x;
printf("Enter data(-1 for no node):");
scanf("%d",&x);
if(x==-1)
return NULL;
p=(node*)malloc(sizeof(node));
p->data=x;
PAGE NO. 78
printf("Enter left child of %d:\n",x);
p->left=create();
printf("Enter right child of %d:\n",x);
p->right=create();
return p;
}
void main()
{
node *root;
clrscr();
root=create();
printf("\nThe preorder traversal of tree is: ");
preorder(root);
getch();
}
PAGE NO. 79
OUTPUT:
PAGE NO. 80
PAGE NO.81
#include<stdio.h>
#include<conio.h>
node *create()
{
node *p;
int x;
printf("Enter data(-1 for no node):");
scanf("%d",&x);
if(x==-1)
return NULL;
p=(node*)malloc(sizeof(node));
p->data=x;
printf("Enter left child of %d:\n",x);
p->left=create();
printf("Enter right child of %d:\n",x);
PAGE NO. 82
p->right=create();
return p;
}
void main()
{
node *root;
clrscr();
root=create();
printf("\nThe Inorder traversal of tree is: ");
inorder(root);
getch();
}
PAGE NO. 83
OUTPUT:
PAGE NO. 84
#include<stdio.h>
#include<conio.h>
typedef struct node
{
int data;
struct node *left;
struct node *right;
} node;
node *create()
{
node *p;
int x;
printf("Enter data(-1 for no node):");
scanf("%d",&x);
if(x==-1)
return NULL;
p=(node*)malloc(sizeof(node));
p->data=x;
printf("Enter left child of %d:\n",x);
p->left=create();
printf("Enter right child of %d:\n",x);
p->right=create();
PAGE NO. 85
return p;
}
void main()
{
node *root;
clrscr();
root=create();
printf("\nThe Postorder traversal of tree is: ");
postorder(root);
getch();
}
PAGE NO. 86
OUTPUT:
PAGE NO. 87
#include <stdio.h>
#include <stdlib.h>
struct TreeNode
{
int data;
struct TreeNode *leftChildNode;
struct TreeNode *rightChildNode;
};
int main()
{
int ch, num, num1;
printf("\nSelect a choice from the menu
below\n---------------------------------------------.");
printf("\n1. Insert a node.");
printf("\n2. Search for a node.");
printf("\nSelect a choice from the menu below.");
printf("\nChoice: ");
PAGE NO. 89
scanf("%d", &ch);
do
{
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);
}
} while(choice!=3);
return 0;
}
OUTPUT:
PAGE NO. 90
PAGE NO. 91
ALGORITHM:
step 1: start
step 2: declare variables num,i,j,temp & array[] of integers
step 3: read total number of elements as num
step 4: set i=0, read elements as array[i]
step 5: set i=o, repeat step to until i<num
step 6: set j=i+1, repeat step to until j<num
step 7: if (array[i] > array[j])
C CODE:
#include<stdio.h>
#include<conio.h>
int main()
{
PAGE NO. 92
int array[100],num,i, j, temp;
clrscr();
printf( "Enter Total Number Of Elements: ");
scanf("%d",&num);
OUTPUT:
PAGE NO. 94
ALGORITHM:
step 1: start
step 2: declare variable n,i,j,position,swap & array as a[] of
integers
step 3: read number of elements as n
step 4: read n number to array a[]
step 5: set i=0, repeat step 6 to step 10 until i<n-1
step 6: set position=i
step 7: set j=i+1, repeat step 7 to step 9 until j<n
step 8:
if a[position] > a[j]
set position=j;
if position != i
set swap=a[i];
set a[i]=a[position];
set a[position]=swap;
step 9: j++
step 10: i++
step 11: stop
C CODE:
#include <stdio.h>
int main()
PAGE NO. 95
{
int a[100], n, i, j, position, swap;
clrscr();
printf("\nEnter number of elements\t");
scanf("%d", &n);
printf("Enter %d Numbers\n", n);
OUTPUT:
PAGE NO. 97
ALGORITHM:
step 1: start
step 2: declare variablesn,,d,t,flag=0 & array[] of integers
step 3: read n as number of elements read n elements
step 4: set c=0, read n elements as array[c]
step 5: set c=1, repeat step 6 to 10 until c<=n-1
step 6: set t=array[c]
step 7: set d=c-1, repeat step 8 to 9 until d>=0
step 8:
if array[d] > t
set array[d+1] = array[d]
set flag = 1
else
break
if (flag)
set array[d+1] = t;
step 9: d--
step 10: c++
step 11: write sorted list array[c]
step 12: stop
C CODE:
#include <stdio.h>
int main()
{
PAGE NO. 98
int n, array[1000], c, d, t, flag = 0;
clrscr();
printf("Enter number of elements\n");
scanf("%d", &n);
getch();
return 0;
}
OUTPUT:
PAGE NO. 100
C CODE:
#include<stdio.h>
#include<conio.h>
void quick_sort(int, int);
int arr_sort[100];
int main()
{
int i,num;
clrscr();
printf("\nSimple Quick Sort Example - Functions and
Array\n");
printf("Enter The Total Number Of Elements\t");
scanf("%d",&num);
printf("\nEnter %d Elements for Sorting\n", num);
for (i = 0; i <num; i++)
scanf("%d", &arr_sort[i]);
quick_sort(0,num-1);
if (f < l)
{
p = f;
i = f;
j = l;
while (i < j)
{
while (arr_sort[i] <= arr_sort[p] && i < l)
i++;
while (arr_sort[j] > arr_sort[p])
j--;
if (i < j)
{
t = arr_sort[i];
arr_sort[i] = arr_sort[j];
arr_sort[j] = t;
}
}
PAGE NO. 102
t = arr_sort[p];
arr_sort[p] = arr_sort[j];
arr_sort[j] = t;
quick_sort(f, j - 1);
quick_sort(j + 1, l);
}
}
OUTPUT:
M.A.N