Home > Back-end >  C program design problem
C program design problem

Time:10-22

#include
#include
#include
#include
#include
using namespace std;
Struct node of hashlian//define a hash table storage structure
{
Int the key;//store the keyword
Hashlian * next;//address pointer
Int Score;//score
Int the age;
String xingbie;
string name;
};
Void main ()
{
Int m=0;//
int i=0;//
Int j=0;//auxiliary variable
Int weizhi=0;//corresponding node location to the elements of
Int the find=0;//records to find the element
Hashlian * data;//store operating data
Hashlian * p1=NULL;
Hashlian * p2=NULL;//points to the nodes of the auxiliary pointer
Hash hashlian *=NULL;
Cout<" Number of input data ";
Cin> m;//input hash table long
Hash=new hashlian [m].//store the hash table
data=https://bbs.csdn.net/topics/new hashlian [m].//dynamic open storage
For (int ii=0; Ii{
Hash [ii]. Key=1;
Hash [ii] next=NULL;
}
Cout<" The input data (from input - 1)!" Cout<" The first: ";
Cout<" Please input points respectively, age, gender, name & lt; "" Cin> Data [I] Score> Data [I] age> Data [I] xingbie> Data [I]. Name;
While (data [I]. Score!=1)//cycle input for operating data
{
If (i{
i++;
Cout<" The first "& lt; Cin> Data [I] Score> Data [I] age> Data [I] xingbie> Data [I]. Name;
}
The else
{
Cout<" Crossing the line!" }
}
J=I;
for(i=0; i{
Weizhi=data [I] Score % m;//positioning is stored
If (hash [weizhi] key=1)//if the current elements directly stored
{
Hash [weizhi] key=data [I] Score;
Hash [weizhi]. Age=data [I] the age;
Hash [weizhi] xingbie=data [I] xingbie;
Hash [weizhi]. Name=data [weizhi]. Name;
}
The else
{
P1=& amp; Hash [weizhi];
The p2=p1 - & gt; Next;
While (p2! P2=NULL)//control always point to the last node under a
{
P1=p2;
The p2=p2 - & gt; Next;
}
The p2=new hashlian;
The p2 - & gt; Key=data [I] Score;//dynamic application space for storage and then insert
The p2 - & gt; Age=data [I] the age;
The p2 - & gt; Name=data [I] xingbie;
The p2 - & gt; Name=data [I]. Name;
The p2 - & gt; Next=NULL;
P1 - & gt; Next=p2;
}
}
Cout<" Input search data: "; Cin> The find.
Weizhi=find % m;//location to find the data should be stored in
P1=& amp; Hash [weizhi];
While (p1!=NULL)//starting from the first position loop through until the last node under a
{
If (p1 - & gt; Key==find)
{
Cout<" To find success!" break;
}
P1=p1 - & gt; Next;
}
If (p1==NULL)//still no lookup fails after all find
{
Cout<" To find the failure!" }

}
The teacher asked us to write curriculum design, want to use an array list method to solve the conflict, but I want to use structure, or the class to write, I always not clear thinking, want to have increase, delete, search functions,,,,,
  • Related