Experiment – 1 (a)
Aim – Write a program to implement Bubble Sort on an array.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,j,n,temp,k;
clrscr();
printf(“Enter limit: “);
scanf(“%d”,&n);
printf(“Enter array elements: “);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
for(i=1;i<=n-1;i++)
{
for(j=0;j<n-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
/* for(k=0;k<n;k++)
{
printf(“%d “,a[k]);
}
printf(” “); */
}
printf(“Sorted array: “);
for(i=0;i<n;i++)
printf(“%d “,a[i]);
getch();
}
Output:
Enter limit: 5
Enter array elements: 1 52 3 2 4
Sorted array: 1 2 3 4 52
Experiment – 1 (b)
Aim – Write a program to implement Selection Sort on an array.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,j,n,temp,k;
clrscr();
printf(“Enter limit :”);
scanf(“%d”,&n);
The Term Paper on Program Development and Evaluation
Early Childhood Education focuses on the education, language, culture, development and care of young children. As a profession, Early Childhood Education has emerged as one of the major vehicles for child-advocacy in the provision of accessible, high-quality child care and pre-school education. Child care, in this society of increasingly busy working couples, is an important service in the ...
printf(“Enter array elements: “);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
/* for(k=0;k<n;k++)
{
printf(“%d “,a[k]);
}
printf(” “); */
}
printf(“Sorted array: “);
for(i=0;i<n;i++)
printf(“%d “,a[i]);
getch();
}
Output:
Enter limit: 7
Enter array elements: 1 52 32 2 4 7 8
Sorted array: 1 2 3 4 7 8 32 52
Experiment – 2 (a)
Aim – Write a program to implement Linear Search on an array.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,n,num,flag=0;
clrscr();
printf(“Enter limit: “);
scanf(“%d”,&n);
printf(“Enter array elements: “);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Enter number to be searched: “);
scanf(“%d”,&num);
for(i=0;i<n;i++)
{
if(a[i]==num)
{
flag=1;
printf(“Number found at position %d in the array”,i+1);
break;
}
}
if(flag==0)
{
printf(“Number not found!”):
}
getch();
}
Output:
Enter limit: 7
Enter array elements: 1 52 32 2 4 7 8
Enter number to be searched: 32
Number found at position 3 in the array
Experiment – 2 (b)
Aim – Write a program to implement Binary Search on an array.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int i,start,last,mid,n,num,a[10],flag=0;
clrscr();
printf(“Enter limit: “);
scanf(“%d”,&n);
The Term Paper on Conversion Of Number Systems
The number is a symbol or a word used to represent a numeral, while a system is a functionally related groups of elements, so as whole, a number is set or group of symbols to represent numbers or numerals. In other words, any system that is used for naming or representing numbers is a number system. We are quite familiar with decimal number system using ten digits. However digital devices and ...
printf(“Enter array elements: “,n);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Enter value to be searched: “);
scanf(“%d”,&num);
start=0;
last=n-1;
while(start<=last)
{
mid=(start+last)/2;
if (a[mid]<num)
start=mid+1;
else
if(a[mid]==num)
{
flag=1;
printf(“Number found at position %d in the array”,mid+1);
break;
}
else
last=mid-1;
}
if(flag==0)
printf(“Number not found in the array”);
getch();
}
Output:
Enter limit: 7
Enter array elements: 1 2 4 7 8 32 52
Enter number to be searched: 32
Number found at position 6 in the array
Experiment – 3 (a)
Aim – Write a program to implement Quick Sort on an array.
Program:
#include<stdio.h>
#include<conio.h>
void quicksort(int [10],int,int);
int main()
{
int i,a[10],n;
clrscr();
printf(“Enter limit: “);
scanf(“%d”,&n);
printf(“Enter array elements: “);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
quicksort(a,0,n-1);
printf(“Sorted array: “);
for(i=0;i<n;i++)
{
printf(“%d “,a[i]);
}
getch();
}
void quicksort(int a[10],int low,int high)
{
int pivot,j,temp,i;
if(low<high)
{
pivot=low;
i=low;
j=high;
while(i<j)
{
while(a[i]<=a[pivot] && i<high)
i++;
while(a[j]>a[pivot])
j–;
if(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[pivot];
a[pivot]=a[j];
a[j]=temp;
The Essay on Acetylation Of Ferrocene Start Material
Acetylation of Ferrocene 17. October 1996 Experiment #7 Introduction In this lab we will be utilizing the Friedel Crafts process of ferrocene. Ferrocene is an atom of iron bounded by two aromatic rings. We will use some reagents that will cause the ferrocene to add either one acetyl group to an aromatic ring or add two acetyl groups to each of the aromatic rings. In order to determine how well ...
quicksort(a,low,j-1);
quicksort(a,j+1,high);
}
}
Output:
Enter limit: 5
Enter array elements: 5 14 12 4 1
Sorted array: 1 4 5 12 15
Experiment – 3 (b)
Aim – Write a program to implement Insertion Sort on an array.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,temp,n,k,key;
clrscr();
printf(“Enter limit: “);
scanf(“%d”,&n);
printf(“Enter array elements: “);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
for(i=1;i<=n-1;i++)
{
key=i;
while(key>0 && a[key]<a[key-1])
{
temp=a[key];
a[key]=a[key-1];
a[key-1]=temp;
key–;
}
/* for(k=0;k<n;k++)
{
printf(“%d “,a[k]);
}
printf(” “); */
}
printf(“Sorted array:”);
for(i=0;i<n;i++)
printf(“%d “,a[i]);
getch();
}
Output:
Enter limit: 5
Enter array elements: 154 544 41 445 4
Sorted array: 4 41 154 445 544
Experiment – 4
Aim – Write a program to implement Linked List
Program:
#include<stdio.h>
#include<conio.h>
struct stu
{
int rollno;
char name[30];
struct stu *link;
};
struct stu *start=NULL,*temp,*newnode,*next;
main()
{
int ch,rn,pos,flag=0,k=0;
clrscr();
do
{
printf(” ———————————–Main Menu————————————“);
printf(” 1.Insert node at end”);
printf(” 2.Insert node at beginning”);
printf(” 3.Insert node at specific position”);
printf(” 4.Delete a node using data value”);
printf(” 5.Display the list”);
The Essay on Virtual Cut Through Routing Message Packet Node
Before a message can be passed to its target, it has to be formed; the message is enveloped inside a packet, which is formed by putting the address information of the target as a header of the actual message, so that the destination of the message and its size etc. can be read before the actual message is received. The actual message is then encoded in order to lessen transmittal time. This ...
printf(” 6.Exit”);
printf(” —————————————————————————————“);
printf(” Enter choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
newnode=(struct stu*)malloc(sizeof(struct stu));
printf(“Enter roll number and name:”);
scanf(“%d %s”,&newnode->rollno,newnode->name);
if(start==NULL)
{
start=newnode; newnode->link=NULL;
}
else
{
temp=start;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=newnode;
newnode->link=NULL;
}
break;
case 2:
newnode=(struct stu*)malloc(sizeof(struct stu));
printf(“Enter roll number and name:”);
scanf(“%d %s”,&newnode->rollno,newnode->name);
if(start==NULL)
{
start=newnode;
newnode->link=NULL;
}
else
{
newnode->link=start;
start=newnode;
}
break;
case 3:
newnode=(struct stu*)malloc(sizeof(struct stu));
printf(“Enter roll number and name:”);
scanf(“%d %s”,&newnode->rollno,newnode->name);
printf(“Enter position:”);
scanf(“%d”,&pos);
temp=start;
if(pos==1)
{
newnode->link=start;
start=newnode;
}
else
{
while(pos>2)
{
if(temp->link==NULL)
{
printf(“Position not existing”);
flag=1;
break;
}
temp=temp->link;
pos–;
}
The Essay on Position Null Iterator Node List
#include #include #include using name space std; class List; class Iterator; class Node{public: / Constructs a node with a given data value. @param s the data to store in this node /Node (string s); private: string data; Node previous; Node next; friend class List; friend class Iterator; }; class List{public: / Constructs an empty list; /List (); / Appends an element to the list. @param s the ...
if(flag==0)
{
newnode->link=temp->link;
temp->link=newnode;
}
}
break;
case 4:
printf(“Enter roll number:”);
scanf(“%d”,&rn);
if(start->rollno==rn)
{
printf(“Deleting 1st node %d”,start->rollno);
next=start;
start=start->link;
free(next);
}
else
{
temp=start;
next=start->link;
while(1)
{
if(next->rollno==rn)
{
temp->link=next->link;
free(next);
flag=1;
break;
}
else
{
next=next->link;
temp=temp->link;
}
}
if(flag==0)
printf(“Element not found!”);
}
break;
case 5:
temp=start;
if(temp==NULL)
printf(“Linked List is empty”);
else
{
while(temp!=NULL)
{
printf(“%d %s “,temp->rollno,temp->name);
temp=temp->link;
}
}
break;
case 6:
exit();
}
}while(1);
getch();
}
Output:
———————————–Main Menu————————————
1.Insert node at end”
2.Insert node at beginning
3.Insert node at specific position
4.Delete a node using data value
5.Display the list
6.Exit
—————————————————————————————
Enter choice:1
Enter roll number and name:1 Kapil
———————————–Main Menu————————————
The Term Paper on Short Scene Door Room Enter
Resident Evil 3-Nemesis Bio Hazard 3-Last Escape -- Faqs/Walkthrough -- [by Rann Yong]Last update: October 1 st, 1999 Table of Contents 01. Intro 02. What's New 03. Controls 04.Characters 05. Walkthrough. September 28 th, daylight... II. October 1 st, night...06. Secrets 07. Mercenaries Game 08. Rank/ Grade 09. Miscellaneous 10. About 11.Special Thanks 01. Intro This is the first faq/ walk through ...
1.Insert node at end”
2.Insert node at beginning
3.Insert node at specific position
4.Delete a node using data value
5.Display the list
6.Exit
—————————————————————————————
Enter choice:2
Enter roll number and name:2 Ritesh
———————————–Main Menu————————————
1.Insert node at end”
2.Insert node at beginning
3.Insert node at specific position
4.Delete a node using data value
5.Display the list
6.Exit
—————————————————————————————
Enter choice:3
Enter roll number and name:3 Megha
Enter position:2
———————————–Main Menu————————————
1.Insert node at end”
2.Insert node at beginning
3.Insert node at specific position
4.Delete a node using data value
5.Display the list
6.Exit
—————————————————————————————
Enter choice:5
2 Ritesh
3 Megha
1 Kapil
———————————–Main Menu————————————
1.Insert node at end”
2.Insert node at beginning
3.Insert node at specific position
4.Delete a node using data value
5.Display the list
6.Exit
—————————————————————————————
Enter choice:4
Enter roll number:1
———————————–Main Menu————————————
1.Insert node at end”
2.Insert node at beginning
3.Insert node at specific position
4.Delete a node using data value
5.Display the list
6.Exit
—————————————————————————————
Enter choice:5
2 Ritesh
3 Megha
———————————–Main Menu————————————
1.Insert node at end”
2.Insert node at beginning
3.Insert node at specific position
4.Delete a node using data value
5.Display the list
6.Exit
—————————————————————————————
Enter choice:6
Experiment – 5
Aim – Write a program to implement Stack
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int stack[5],ch,top=-1;
clrscr();
do
{
printf(” ———————————Main Menu———————————-“);
printf(” 1.Push()”);
printf(” 2.Pop()”);
printf(” 3.Display”);
printf(” 4.Exit”);
printf(” —————————————————————————-“);
printf(” Enter choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
if(top==4)
printf(“Stack Qverflow”);
else
{
top=top+1;
printf(“Enter data:”);
scanf(“%d”,&stack[top]);
}
break;
case 2:
if(top==-1)
printf(“Stack Underflow”);
else
{
printf(“Item being popped:%d”,stack[top]);
top=top-1;
}
break;
case 3:
if(top==-1)
printf(“Stack is empty”);
else
{
int i=0;
while(i<=top)
{
printf(“%d “,stack[i]);
i++;
}
}
break;
case 4:
exit();
}
}while(1);
getch();
}
Output:
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:1
Enter data:1
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:1
Enter data:2
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:1
Enter data:3
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:1
Enter data:4
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:3
4 3 2 1
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:2
Item being popped:4
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:2
Item being popped:3
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:3
2 1
———————————Main Menu———————————-
1.Push()
2.Pop()
3.Display
4.Exit
———————————————————————————–
Enter choice:4
Experiment – 6
Aim – Write a program to implement Queue
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int queue[50],ch,F=-1,R=-1,i;
clrscr();
do
{
printf(” ———————————Main Menu———————————-“);
printf(” 1.Insert an element”);
printf(” 2.Delete an element”);
printf(” 3.Display elements”);
printf(” 4.Exit”);
printf(” ———————————————————————————-“);
printf(” Enter choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:
if(R>=49)
printf(“Queue Qverflow”);
else
{
R=R+1;
printf(“Enter data:”);
scanf(“%d”,&queue[R]);
if(F==-1)
{
F=F+1;
}
}
break;
case 2:
if(R<F || F==-1)
printf(“Queue Underflow”);
else
{
printf(“Element being deleted:%d”,queue[F]);
queue[F]=0;
F=F+1;
}
break;
case 3:
if(F>R)
printf(“Queue is empty”);
else
{
for(i=F;i<=R;i++)
printf(“%d “,queue[i]);
}
break;
case 4:
exit();
}
}while(1);
getch();
}
Output:
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:1
Enter data:1
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:1
Enter data:2
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:1
Enter data:3
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:1
Enter data:4
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:3
1 2 3 4
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:2
Element being deleted:1
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:2
Element being deleted:2
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:3
3 4
———————————Main Menu———————————-
1.Insert an element
2.Delete an element
3.Display elements
4.Exit
———————————————————————————-
Enter choice:4
Experiment – 7
Aim – Write a program to implement Tree.
Program:
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct node
{
struct node *left;
int data;
struct node *right;
};
void main()
{
void insert(struct node **,int);
void inorder(struct node *);
void postorder(struct node *);
void preorder(struct node *);
struct node *ptr;
int n,i,num;
ptr=NULL;
ptr->data=NULL;
clrscr();
printf(” Enter the number of nodes : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf(“Enter data: “);
scanf(“%d”,&num);
insert(&ptr,num);
}
printf(” Inorder Traversal : “);
inorder(ptr);
getch();
printf(” Preorder Traversal : “);
preorder(ptr);
getch();
printf(” Postorder Traversal: “);
postorder(ptr);
getch();
}
void insert(struct node **p,int num)
{
if((*p)==NULL)
{
(*p)=(struct node *)malloc(sizeof(struct node));
(*p)->left=NULL;
(*p)->right=NULL;
(*p)->data=num;
return;
}
else
{
if(num==(*p)->data)
{
printf(” REPEATED ENTRY! ERROR VALUE REJECTED. “);
return;
}
if(num<(*p)->data)
{
insert(&((*p)->left),num);
}
else
{
insert(&((*p)->right),num);
}
}
return;
}
void inorder(struct node *p)
{
if (p!=NULL)
{
inorder(p->left);
printf(“%d “,p->data);
inorder(p->right);
}
else
return;
}
void preorder(struct node *p)
{
if(p!=NULL)
{
printf(“%d “,p->data);
preorder(p->left);
preorder(p->right);
}
else
return;
}
void postorder(struct node *p)
{
if(p!=NULL)
{
postorder(p->left);
postorder(p->right);
printf(“%d “,p->data);
}
else
return;
}
Output:
Enter the number of nodes : 4
Enter data: 1
Enter data: 2
Enter data: 4
Enter data: 3
Inorder Traversal : 1 2 3 4
Preorder Traversal : 1 2 4 3
Postorder Traversal: 3 4 2 1
Experiment – 8
Aim – Write a program to implement Graph.
Program:
#include<stdio.h>
#include<stdlib.h>
#define SIZE 10
#define T 1
#define F 0
#define NULL 0
struct edge
{
int terminal;
struct edge *next;
};
struct vertex
{
int visit;
int vertex_no;
char info;
int path_length;
struct edge *edge_ptr;
};
void table(int ,int matrix[SIZE][SIZE],struct vertex vert[SIZE]);
struct edge *insert_vertex(int ,struct edge*);
void dfs(int ,int *dist,struct vertex vert[SIZE]);
void output(int ,int a[SIZE][SIZE]);
void input(int ,int a[SIZE][SIZE]);
struct edge *insert_vertex(int vertex_no,struct edge *first)
{
struct edge *new1,*current;
new1=(struct edge*)malloc(sizeof(struct edge));
new1->terminal=vertex_no;
new1->next=NULL;
if(!first)
return new1;
for(current=first;current->next;current=current->next);
current->next=new1;
return first;
}
void table(int vertex_num,int matrix[SIZE][SIZE],struct vertex vert[SIZE])
{
int i,j;
for(i=0;i<vertex_num;i++)
{
vert[i].visit=F;
vert[i].vertex_no=i+1;
vert[i].info=’A’+i;
vert[i].path_length=0;
vert[i].edge_ptr=NULL;
}
for(i=0;i<vertex_num;i++)
{
for(j=0;j<vertex_num;j++)
{
if(matrix[i][j]>0)
{
vert[i].edge_ptr=insert_vertex(j,vert[i].edge_ptr);
}
}
}
}
void dfs(int index,int *dist,struct vertex vert[SIZE])
{
struct edge *link;
vert[index].visit=T;
vert[index].path_length=*dist;
*dist+=1;
for(link=vert[index].edge_ptr;link;link=link->next)
if(vert[link->terminal].visit==F)
dfs(link->terminal,dist,vert);
}
void input(int number,int a[SIZE][SIZE])
{
int i,j;
printf(“Input the adjacency matrix: “);
for(i=0;i<number;i++)
{
for(j=0;j<number;j++)
scanf(“%d”,&a[i][j]);
}
}
void output(int number,int a[SIZE][SIZE])
{
int i,j;
printf(“Adjacency Matrix: “);
for(i=0;i<number;i++)
{
for(j=0;j<number;j++)
{
printf(“%dt”,a[i][j]);
}
printf(” “);
}
}
void main()
{
int i,number,index,dist,a[SIZE][SIZE];
struct vertex vert[SIZE];
struct edge *list;
clrscr();
printf(” Input the number of vertices: “);
scanf(“%d”,&number);
input(number,a);
clrscr();
output(number,a);
table(number,a,vert);
printf(” Input the starting vertex 0-%d: “,number-1);
scanf(“%d”,&index);
dist=0;
dfs(index,&dist,vert);
printf(” ttt==================== “);
printf(“ttt Path Length of the vertex %c”,vert[index].info);
printf(” ttt==================== “);
printf(” VertextLengthtVertex Complexity”);
printf(” ——t——t—————– “);
for(i=0;i<number;i++)
{
printf(” %ct%dt”,vert[i].info,vert[i].path_length);
for(list=vert[i].edge_ptr;list;list=list->next)
{
printf(” “);
putchar(list->terminal+’A’);
}
}
getch();
}
Output:
Input the number of vertices: 2
Input the adjacency matrix: 0 1 0 1
Adjacency Matrix:
0 1
0 1
Input the starting vertex 0-1: 0
========================
Path Length of the vertex A
========================
Vertex Length Vertex Complexity
——— ———- ————————
A 0 B
B 1 B