Dsa Proj
Dsa Proj
Dsa Proj
(INTO C++)
SUBMITTED BY:
ABID QADOOS
M.SC-1 EVENING
SUBMITTED TO:
ALMIGHTY ALLAH
THE MOST
BENEFICENT,
THE MOST
MERCIFUL
MY LOVING PARENTS
&
COLLEAGUES
TABLE OF CONTENTS.......................................................................................................................................5
PROGRAM CODE
#include<iostream.h>
#include<conio.h>
#include<alloc.h>
int a[100]; int n,i,j,k,item,stsize,qsize; int lb=0; int choice;
int st[10];int cq[10]; int top=-1;int q[10];int r=-1;int f=-1;
DSA PROJECT ALGOS IMPLEMENTATION INTO C++ 5
void heading(); void welcome(); void mmenu();
void array(); void traverse(); void insertion(); void deletion(); void search();
void sort(); void bubblesort(); void insertsort(); void selectsort(); void shellsort();
void merging();
void stack(); void push(); void pop();
void queue(); void qinsert(); void qdelete(); void cqinsertion(); void cqdelete();
void linklist(); void slinklist(); void sll_traverse();
void sll_insertion(); void linkaf(); void linkal(); void linkbg(); void linkag();
void sll_deletion(); void linkaf_d(); void linkal_d(); void linkag_d();
void dlinklist(); void dll_traverse(); void dll_insertion(); void dll_ins_af(); void
dll_ins_al(); void dll_ins_bg(); void dll_ins_ag(); void dll_deletion(); void dll_del_af();
void dll_del_al(); void dll_del_ag();
struct link2
{
int info;
link2 *next;
};
struct dlink_list
{
int info;
dlink_list *next;
dlink_list *previous;
};
1. int main()
{
clrscr();
welcome();
mmenu();
getch();
DSA PROJECT ALGOS IMPLEMENTATION INTO C++ 6
return 0;
}
2. void heading()
{
clrscr();
cout<<"*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*";
cout<<"\n\n\n\t\t\tDATA STRUCTURE & ALGORITHMS";
cout<<"\n\n\t\t\tPROJECT OF ALGOS IMPLEMENTATION INTO C++";
cout<<"\n\n\n*****************************************************";
}
3. void welcome()
{
clrscr();
heading();
for (int i=1;i<10;i++)
{
cout<<"\n\t\t\t\t*!!*";
}
cout<<"\n\n \n\n Submitted By:- ABID QADOOS AWAN ";
cout<<"\n\@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n";
cout<<"\n\n\n\n\n Submitted To:- NAUMAN QADEER SB.";
for (int j=1;j<10;j++)
{
cout<<"\n\n\t\t\t\t*!!*";
}
cout<<"\n********************************************************";
getch();
clrscr();
}
4. void mmenu()
{
DSA PROJECT ALGOS IMPLEMENTATION INTO C++ 7
clrscr();
while (choice!=-1)
{
clrscr();
heading();
cout<<"*\n*\n*\n Enter your choice to choose a data structure type";
cout<<"*\n*\n\t\t\t 1 = ARRAY\n";
cout<<"*\n*\n\t\t\t 2 = STACK\n";
cout<<"*\n*\n\t\t\t 3 = QUEUE\n\n";
cout<<"*\n*\n\t\t\t 4 = LINK LIST \n\n";
cout<<"*\n****************************************************";
cout<<"\n\n PRESS '-1' FOR EXIT\n\n";
cout<<"\n\t Enter Your Choice\t=\t";
cin>>choice;
switch(choice)
{
case 1:
array();
break;
case 2:
stack();
break;
case 3:
queue();
break;
case 4:
linklist();
break;
default:
cout<<" Press Correct Option";
break;
}
}
clrscr();
5. void array()
{
clrscr();
heading();
cout<<"\n\n\t\tEnter the no of elements in Array b/w (1-100)\t=\t";
cin>>n;
while (choice!=-1)
clrscr();
heading();
cout<<"\n\n\n Enter your choice to choose a operation on array";
cout<<"\n\n\t\t\t TRAVERSING>>.>.>.>.>.>.>>\t1\n";
cout<<"\n\n\t\t\t INSERTION>>.>.>.>.>.>.>.>\t2\n";
cout<<"\n\n\t\t\t DELETION>>.>.>.>.>.>.>.>>\t3\n";
cout<<"\n\n\t\t\t SEARCHING>>.>.>.>.>.>..>>\t4\n";
cout<<"\n\n\t\t\t MERGING>>.>.>.>.>.>.>.>.>\t5\n";
cout<<"\n\n\t\t\t SORTING>>.>.>.>.>.>.>.>.>\t6\n";
cout<<"\n\n\t\t\t EXIT>>.>.>.>.>.>.>.>.>.>>\n\n";
cout<<"\n\n\t\t ENTER YOUR CHOICE HERE\t";
cin>>choice;
switch(choice)
{
case 1:
clrscr();
traverse();
break;
6. void traverse()
{
clrscr();
heading();
cout<<"\n\n TRAVERSING OF ARRAY ";
cout<<"\n***********************************************************";
if(a[i]<lb)
{
cout<<"\n ARRAY IS EMPTY";
DSA PROJECT ALGOS IMPLEMENTATION INTO C++ 10
array();
}
cout<<"\n\n\n******************************************************\n";
for (j=0;j<n;j++)
{
cout<<"\t"<<(j+1)<<" Entered value is\t" <<a[j]<<"\n\n";
}
getch();
}
7. void insertion()
{
heading();
cout<<"\n\n\t\t\t\tINSERTION IN ARRAY";
cout<<"\n**********************************************************";
cout<<"\nEnter the position where insertion take place\t=\t";
cin>>k;
cout<<"\nEnter the item which may be inserted at given position\t=\t";
cin>>item;
if ((n>=20)||((k<0)||(k>(n+1))))
{
cout<<"\nInsertion can not take place";
}
for(i=(n-1);i>=k;i--)
{
a[i+1]=a[i];
}
a[k]=item;
n=n+1;
cout<<"\n\n\n No of elements in array"<<n;
cout<<"\n**********************************************************\n";
for (j=1;j<=n;j++)
{
DSA PROJECT ALGOS IMPLEMENTATION INTO C++ 11
cout<<"\n"<<a[j];
}
getch();
}
8. void deletion()
{
clrscr();
heading();
cout<<"\n\t\t\t DELETION IN ARRAY";
cout<<"\n***************************************************************\n";
cout<<"\n\n Enter the position of element u want to delete\t=\t";
cin>>k;
if ((k<lb)||(k>(n-1)))
{
cout<<"deletion can not possible. Array is empty";
getch();
array();
}
else
{
item=a[k];
cout<<"\n\n deleted value is\t=\t"<<item;
for (i=k+1;i<=
(n-1);i++)
a[i-1]=a[i];
n=n-1;
traverse();
getch();
}
}
9. void search()
{
DSA PROJECT ALGOS IMPLEMENTATION INTO C++ 12
int choice;
int item,i,beg,midpos,end;
int count=0;
int j;
clrscr();
heading();
cout<<"\n\nEnter Your Choice for searching type\t";
cout<<"\n\n\n\t\tLinear Search Single>>.>.>.>.>.>.>>\t1\n";
cout<<"\n\n\n\t\tLinear Search Multiple>>.>.>.>.>.>.>>\t2\n";
cout<<"\n\n\n\t\tBinary Search Single>>.>.>.>.>.>.>>\t3\n";
cout<<"\n\n\n\t\tBinary Search Multiple>>.>.>.>.>.>.>>\t4\n\t";
cout<<"\n\n\t\t EXIT >>.>.>.>.>.>.>>";
cout<<"\n\n\t\t ENTER YOUR CHOIVCE\t";
cin>>choice;
switch (choice)
{
case 1:
clrscr();
heading();
cout<<"\t Program for Linear Searching Single";
cout<<"\n\n****************************************************";
cout<<"\nEnter the item to search\t\t=\t";
cin>>item;
for (int j=0; j<n; j++)
if(a[j]==item)
{
cout<<" \n\n\nitem found=\t"<<item;
getch();
}
cout<<"\n\n\n\nitem not found";
getch();
break;
case 2:
clrscr();
if (ptrA>(NA+LBA-1))
while (ptrB<=(NB+LBB)-1)
{
C[ptrC]=B[ptrB];
ptrB=ptrB+1;
ptrC=ptrC+1;
}
else
while (ptrA<=(NA+LBA)-1)
struct link
{
int inf;
link *nxt;
};