MCA SYLLABUS


THEORY - Syllabus

Computer Organization

Problem Solving and Programming

Database Management Systems

Data Structures

Accounting and Financial Management



PRACTICAL - Syllabus



Programming and Data Structures Lab

DBMS Lab

Object Oriented Programming Lab

Design and Analysis of Algorithms Lab

JAVA Programs

Visual Programming

Question Paper

Insertion Sort


Program


#include ”stdio.h”
#include ”conio.h”
int i,j,a[20],n;
void main()
{
clrscr();
printf("MERGE SORT\n");
printf("Enter the no of elements:");
scanf("%d",&n);
for(i=0;I < i="0;I" k="1;k" y="a[k];" i="k-1;I"> =0 && y < a[i]; i--)
a[i+1] = a[i];
a[i+1] = y;
}
}

MERGE SORT

Previous Next


Program

#include “ stdio.h “

#include “ conio.h “

void main()

{

int x[20],n,i;

clrscr();

printf("Merge sort\n");

printf("Enter the number of elements :");

scanf("%d",&n);

printf("Enter the elements\n");

for(i=0;i <>

scanf("%d",&x[i]);

mergesort(x,n);

printf("The sorted list is:\n");

for(i=0;i <>

printf("%d\n",x[i]);

getch();

}

mergesort(x,n)

int x[20],n;

{

int aux[10],i,j,k,l1,l2,size,u1,u2;

size=1;

while(size <>

{

l1=0;

k=0;

while(l1+size < n)

{

l2=l1+size;

u1=l2-1;

u2=(l2+size-1 < n) ? l2+size-1 : n-1;

for(i=l1,j=l2;i < =u1 && j < =u2; k++)

if(x[i] < = x[j])

aux[k] = x[i++];

else

aux[k] = x[j++];

for(;i < =u1;k++)

aux[k]=x[i++];

for(;j < =u2;k++)

aux[k]=x[j++];

l1=u2+1;

}

for(i=l1;k <>

aux[k++] = x[i];

for(i=0;i <>

x[i] = aux[i];

size*=2;

}

}

BREADTH-FRIST TRAVERSAL

Program


#include “ stdio.h “
#include “ conio.h “
#define n 10

void bfs(int adj[][n],int visited[],int start)
{
int q[n],rear=-1,front=-1,i;
q[++rear]=start;
visited[start]=1;
while(rear!=front)
{

start=q[++front];
if(start==q)
printf("10-");
else
printf("%c-",start+65);
for(i=0;i < n;i++) { if(adj[start][i]&&!visited[i]) { q[++rear]=i; visited[i]=1; } } } } void main() { int adj[n][n]={{0,1,1,0,0,0,0,0,0,1},{0,0,0,0,1,0,0,0,0,1}, {0,0,0,0,1,0,1,0,0,0},{1,0,1,0,0,1,1,0,0,1}, {0,0,0,0,0,0,1,1,0,0},{0,0,0,1,0,0,0,1,0,0}, {0,0,0,0,0,0,0,1,1,1},{0,0,1,0,0,0,0,0,0,0}, {0,0,0,1,0,0,0,0,0,0},{0,0,1,0,0,0,0,1,1,0}};.
int visited[n]={0}; clrscr();
printf("\n\t\t\t------------------------------");
printf("\n\n");
printf("BFS Traverse:");
bfs(adj,visited,0);
getch();

}

Output


BFS Traverse: A-B-C-J-E-G-H-I-D-F-

Depth-First Traversal

Previous Next


Program

#include “ stdio.h “

#include “ conio.h “

#define max 5

void dfs(int adj[][max],int visited[],int start)

{

int stack[max],top=-1,i;

printf("%c-",start+65);

visited[start]=1;

stack[++top]=start;

while(top!=-1)

{

start=stack[top];

for(i=0;i <>

{

if(adj[start][i]&&visited[i]==0)

{

stack[++top]=i;

printf("%c-",i+65);

visited[i]=1;

break;

}

}

if(i==max)

top--;

}

}

void main()

{

int adj[max][max]={{0,0,1,1,0},

{0,0,0,0,0},

{0,1,0,1,1},

{0,0,0,0,1},

{0,0,0,1,0}};

int visited[max]={0};

clrscr();

printf("\n\t\t\tDEPTH-FRIST SEARCH TRAVERSAL");

printf("\n\t\t\t--------------------------------------------------");

printf("\n\n");

printf("DFS Traverse:");

dfs(adj,visited,0);

getch();

}

Output

DFS Traverse: A-C-B-D-E-

Binary Tree Traversal

Previous Next


Program



#include "stdio.h"

#include "conio.h"

#include "alloc.h"

#include "stdlib.h"

struct node

{

struct node *lc;

int data;

struct node *rc;

};

struct node *tree,*btree=NULL,*newnode,*temp;

struct node *getnode();

struct node *createbtree();

struct node *insertnode(struct node *btree,struct node *temp);

void inorder(struct node *btree);

void preorder(struct node *btree);

void postorder(struct node *btree);

void main()

{

int cho;

clrscr();

printf("\n\t\tBinary Tree Traversal\n");

printf("\n\t\t---------------------------\n");

btree=createbtree();

do{

printf("\nBinary Tree Traversal\n");

printf("1.Preorder Traversal\n2.Inorder Traversal\n");

printf("3.Postorder Traversal\n4.Exit");

printf("\nEnter ur choice:");

scanf("%d",&cho);

if(btree==NULL)

printf("\nBinary tree is empty\n");

switch(cho)

{

case 1:

printf("\nPreorder Traversal is:");

preorder(btree);

break;

case 2:

printf("\nInorder Traversal is:");

inorder(btree);

break;

case 3:

printf("\nPostorder Traversal is:");

postorder(btree);

break;

case 4:

exit(0);

getch();

}

}while(cho!=4);

free(btree);

getch();

}

struct node *getnode()

{

newnode=(struct node*)malloc(sizeof(struct node));

printf("\nEnter node's data:");

scanf("%d",&newnode- >data);

newnode- >lc=NULL;

newnode- >rc=NULL;

return(newnode);

}

struct node *createbtree()

{

char ch;

do{

temp=getnode();

btree=insertnode(btree,temp);

fflush(stdin);

printf("\nDo u wish to add data(y/n):");

scanf("%c",&ch);

}while((ch=='Y')||(ch=='y'));

return(btree);

}

struct node *insertnode(struct node *btree,struct node *temp)

{

if(btree==NULL)

return temp;

else if(temp- >data < btree- >data)

btree- >lc=insertnode(btree- >lc,temp);

else if(temp- >data > btree- >data)

btree- >rc=insertnode(btree- >rc,temp);

else if(temp- >data == btree- >data)

{

printf("\nData already exists");

return(btree);

}

return(btree);

}

void inorder(struct node *btree)

{

if(btree!=NULL)

{

inorder(btree- >lc);

printf("%d ",btree- >data);

inorder(btree- >rc);

}

}

void preorder(struct node *btree)

{

if(btree!=NULL)

{

printf("%d ",btree- >data);

preorder(btree- >lc);

preorder(btree- >rc);

}

}

void postorder(struct node *btree)

{

if(btree!=NULL)

{

postorder(btree- >lc);

postorder(btree- >rc);

printf("%d",btree- >data);

}

}



Output


Enter node's data: 5

Do u wish to add data(y/n): y

Enter node's data: 4

Do u wish to add data(y/n): y

Enter node's data: 7

Do u wish to add data(y/n): y

Enter node's data: 3

Do u wish to add data(y/n): y

Enter node's data: 1

Do u wish to add data(y/n): n

Binary Tree Traversal

1.Preorder Traversal

2.Inorder Traversal

3.Postorder Traversal

4.Exit

Enter your choice: 1

Preorder Traversal is: 5 4 3 1 7

Binary Tree Traversal

1.Preorder Traversal

2.Inorder Traversal

3.Postorder Traversal

4.Exit

Enter your choice: 2

Inorder Traversal is: 1 3 4 5 7

Binary Tree Traversal

1.Preorder Traversal

2.Inorder Traversal

3.Postorder Traversal

4.Exit

Enter your choice: 3

Postorder Traversal is: 1 3 4 7 5

Binary Tree Traversal

1.Preorder Traversal

2.Inorder Traversal

3.Postorder Traversal

4.Exit

Enter your choice: 4

QUEUE OPERATION USING LINKED LIST

Previous Next


Program


#include <>
#include <>
#define NULL 0
struct node
{
int data;
struct node *link;
};
struct node *front=NULL,*rear=NULL,*newnode,*temp;
void main()
{
int ch;
clrscr();
printf("\n\t\tQUEUE OPERATION USING LINKED LIST");
printf("\n\t\t--------------------------------------------------------- ");
do
{
printf("\n 1.INSERT\n 2.DELETE\n 3.DISPLAY\n 4.EXIT");
printf("\n Enter Your Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
}
}while(ch!=4);
getch();
}
enqueue()
{
newnode=(struct node*)malloc(sizeof (struct node));
printf("\n Enter The Data :");
scanf("%d",&newnode- >data);
newnode- >link=NULL;
printf("\n The inserted data is:%d",newnode- >data);
if(front==NULL)
front=newnode;
else
rear- >link=newnode;
rear=newnode;
}
dequeue()
{
temp=front;
if(front==NULL)
printf("\n Queue is empty");
else
{
printf("\n The deleted data is:%d",temp- >data);
front=front- >link;
}
free(temp);
}
display()
{
temp=front;
if(front==NULL)
printf("\n Queue is empty");
else
{
printf("\n Queue Values are:");
while(temp!=NULL)
{
printf("\n%d",temp- >data);
temp=temp- >link;
}
}
}


Output

Enter the queue size: 3

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 1

Enter The Data : 5
The inserted data is: 5

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 1

Enter The Data : 10
The inserted data is: 10

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 3

Queue Values are:
5
10

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 2

The deleted data is: 5

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 3

Queue Values are:
10

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 4

QUEUE OPERATION USING ARRAYS


Program


#include <>
#include <>
int n,i,ch,front=-1,rear=-1,s[20],value;
void main()
{
int ch;
clrscr();
printf("\n\t\t QUEUE OPERATION USING ARRAYS");
printf("\n\t\t -------------------------------------------------- ");
printf("\n Enter the queue size:");
scanf("%d",&n);
do
{
printf("\n 1.INSERT\n 2.DELETE\n 3.DISPLAY\n 4.EXIT");
printf("\n Enter Your Choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
}
}while(ch!=4);
getch();
}
enqueue()
{
if(rear==n-1)
printf("\n Queue is full");
else
{
printf("\n Enter The Data :");
scanf("%d",&value);
rear++;
s[rear]=value;
printf("\n The inserted data is:%d",value);
if(front==-1)
front++;
}
}
dequeue()
{

if(front==-1)
printf("\n Queue is empty");
else
{
value=s[front];
printf("\n The deleted data is:%d",value);
if(front==rear)
{
front=-1;
rear=-1;
}
else
front++;
}
}
display()
{
if(front==-1)
printf("\n Queue is empty");
else
{
printf("\n Queue Values are:");

for(i=front;i < =rear;i++) printf("\n%d",s[i]); } } Output

Enter the queue size: 3

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 1

Enter The Data : 5
The inserted data is: 5

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 1

Enter The Data : 10
The inserted data is: 10

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 3

Queue Values are:
5
10








1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 2



The deleted data is: 5
1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 3

Queue Values are:
10

1.INSERT
2.DELETE
3.DISPLAY
4.EXIT
Enter Your Choice: 4