#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void insert(int x[10],int);
void del(int x[],int);
void sort(int x[],int);
void search_seq(int x[],int);
void bin_search(int x[],int);
void show(int x[],int);
void my_delay();
void main_menu();
//***************
int main(){
main_menu();
getch();
return 0;
}
//***************
void my_delay()
{
char x;
gotoxy(50,25);
cout<<"Press any key to continue...";
getch();
main_menu();
}
//*****************
void show(int x[],int a){
clrscr();
for(int i=0;i<a;i++) {
cout<<"Index "<<i+1<<" of array is "<<x[i]<<"\n";
}
my_delay();
}
//******************
void bin_search(int x[],int len){
int top,low;
top=len;
low=0;
int item;
clrscr();
cout<<"Enter number for search:" ;
cin rel='nofollow' onclick='return false;'>>item;
while(low<=top){
int mid=(low+top)/2;
if(x[mid]<item)
low=mid+1;
else if(x[mid]>item)
top=mid-1;
else if (x[mid]==item)
{
clrscr();
cout<<"your result search is index "<<mid;
my_delay();
}
}
clrscr();
cout<<"not found";
my_delay();
}
//**************
void sort(int x[],int len){
for(int i=0;i<len-1;i++)
for(int j=0;j<i;j++)
if (x[j]<x[j+1])
{
int temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
my_delay();
}
//********************
void search_seq(int x[],int a)
{
int item ;
clrscr();
cout<<"Enter value for search:" ;
cin>>item;
for(int i=0;i<a;i++)
if (item==x[i])
{
clrscr();
cout<<"your result search is index "<<i;
my_delay();
}
clrscr();
cout<<"not found";
my_delay();
}
//*********************************
void insert(int x[],int a)
{
clrscr();
for(int i=0;i<a;i++) {
clrscr();
x[i]=0;
cout<<"Enter a number for index "<<i<< " of array:";
cin rel='nofollow' onclick='return false;'>>x[i];
}
clrscr();
cout<<"Insert is success";
my_delay();
}
//*****************
void del(int x[],int a){
char ch;
int item;
clrscr();
cout<<"Enter a value for delete:";
cin>>item;
for(int i=0;i<a;i++)
if (*(x+i)==item) {
clrscr();
cout<<"Are you sure ? y=yes n=no:::";
cin rel='nofollow' onclick='return false;'>>ch;
exit;
}
if (ch=='y'){
*(x+i)=0;
my_delay();
}
else
{
clrscr();
cout<<"Abort by user...";
my_delay();
}
}
//**************************
void exit(){
char x;
clrscr();
gotoxy(20,12);
cout<<"programing by :: fardeen sadeghi";
cin>>x;
exit(0);
}
//**************************
void main_menu(){
int len=10,an,*p;
p=new int[10];
clrscr();
gotoxy(15,6);
cout<<"Wellcome to main menu";
gotoxy(20,12);
cout<<"1.Insert item";
gotoxy(20,14);
cout<<"2.Delete item";
gotoxy(20,16);
cout<<"3.Sort item";
gotoxy(20,18);
cout<<"4.Search sequantioal";
gotoxy(20,20);
cout<<"5.Binary search item";
gotoxy(20,22);
cout<<"6.Show item";
gotoxy(20,24);
cout<<"7.Exit";
gotoxy(20,30);
cout<<"Inser your choice:";
cin>>an;
switch(an){
case 1:
insert(p,len);
case 2:
del(p,len);
case 3:
sort(p,len);
case 4:
search_seq(p,len);
case 5:
bin_search(p,len);
case 6:
show(p,len);
case 7:
exit();
}
}
//*********************