Practical Assignment
Practical Assignment
Practical Assignment
#include <stdio.h>
int main()
scanf("%d", &n);
scanf("%d", &array[c]);
scanf("%d", &search);
first = 0;
last = n - 1;
middle = (first+last)/2;
first = middle + 1;
break;
else
last = middle - 1;
return 0;
OUTPUT –
4. Write a program to create a Binary Search Tree and
display its contents using recursive preorder,
postorder and inorder traversal.
#include <stdio.h>
#include <stdlib.h>
struct node
int data;
};
malloc(sizeof(struct node));
node->data = data;
node->left = NULL;
node->right = NULL;
return(node);
if (node == NULL)
return;
printPostorder(node->left);
printPostorder(node->right);
if (node == NULL)
return;
printInorder(node->left);
printInorder(node->right);
if (node == NULL)
return;
printPreorder(node->left);
printPreorder(node->right);
int main()
printf("\n\nBHAWANA SUMAN\n\n");
struct node *root = newNode(1);
root->left = newNode(2);
root->right = newNode(3);
root->left->left = newNode(4);
root->left->right = newNode(5);
printPreorder(root);
printInorder(root);
printPostorder(root);
getchar();
return 0;
OUTPUT –
3. Write a program to make an Insertion sort of 10
numbers of elements.
#include<stdio.h>
int main(){
scanf("%d",&count);
for(i=0;i<count;i++)
scanf("%d",&number[i]);
for(i=1;i<count;i++){
temp=number[i];
j=i-1;
while((temp<number[j])&&(j>=0)){
number[j+1]=number[j];
j=j-1;
number[j+1]=temp;
for(i=0;i<count;i++)
printf(" %d",number[i]);
return 0; }
OUTPUT –