📄 add_calc.cpp
字号:
/******Don't forget to download*****
*****GRAPHICAL DATA FILE STRUCTURE*****
*****A approach to learn DFS Graphically*****
Only @ http://www.vivekpatel.cjb.net */
//Address Calculation sort
//Programmed by : Vivek Patel
//URL : www.vivekpatel.cjb.net
//Email : vivek_patel9@rediffmail.com
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class add_calc{
struct link{
int num;
link *next;
}*head;
link *hash_table[20];
public :
add_calc();
void getdata();
int process(int);
void display();
};
add_calc :: add_calc(){
for(int i=0;i<20;i++)
{
hash_table[i]->num=i;
hash_table[i]->next=NULL;
}
}
void add_calc :: getdata()
{
int info,rendom;
link *n1,*p,*s;
char ans;
do
{
cout<<endl<<"Enter the info (1 to 100):";
cin>>info;
if(info<1 || info>100)
{
cout<<endl<<"Not possible:";
break;
}
else
{
n1 = new link;
n1->num=info;
n1->next=NULL;
rendom=process(info);
if(hash_table[rendom]->next==NULL)
hash_table[rendom]->next=n1;
else
{
p=hash_table[rendom];
s=p->next;
while(s!=NULL && s->num < info)
{
p=s;
s=s->next;
}
if(s==NULL)
{
p->next=n1;
}
else
{
p->next=n1;
n1->next=s;
}
}
}
cout<<endl<<"do u want to continue[y/n]:";
fflush(stdin);
cin>>ans;
}while(ans!='n');
int i=0;
while(hash_table[i]->next==NULL && i<20)
{
i=i+1;
}
head = hash_table[i]->next;
int j=i+1;
while(j<20)
{
if(hash_table[j]->next!=NULL)
{
p=hash_table[i]->next;
while(p->next!=NULL)
p=p->next;
p->next=hash_table[j]->next;
i=j;
j=j+1;
}
else
j++;
}
}
void add_calc :: display()
{
link *temp=head;
while(temp!=NULL)
{
cout<<endl<<temp->num;
temp=temp->next;
}
cout<<endl<<temp->num;
}
int add_calc :: process(int info)
{
int i=0;
int t=info/10;
for(i=0;i<=t;i++)
{
if(i==0&&i==t)
return(i);
else if(i==t)
return(i);
}
}
void main(){
add_calc a;
clrscr();
a.getdata();
a.display();
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -