Home > Software engineering >  C language and the realization of the time the random data search
C language and the realization of the time the random data search

Time:10-01

[color=# FFFF00] [color=# FFCC00] in the C language an experiment data for
Program can be compiled through, but the connection when it comes to bugs, small white said don't know how to change, a great god, please grant instruction

attached to the connection code:
[/color]-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the Configuration: SCHTB - Win32 Debug -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Linking...
SCHTB. Obj: error LNK2001: unresolved external symbol "int __cdecl random (int)" (? The random @ @ YAHH @ Z)
SCHTB. Obj: error LNK2001: unresolved external symbol "int __cdecl random (int)" (? The random @ @ YAHH @ Z)
SCHTB. Obj: error LNK2001: unresolved external symbol "int __cdecl random (int)" (? The random @ @ YAHH @ Z)
Nafxcwd. Lib (thrdcore. Obj) : error LNK2001: unresolved external symbol __endthreadex
Nafxcwd. Lib (thrdcore. Obj) : error LNK2001: unresolved external symbol __beginthreadex
The Debug/SCHTB. Exe: fatal error LNK1120:3 unresolved externals
An error occurred when execution link. Exe.




SCHTB. CPP code in the

# include & lt; Stdio. H>
# include & lt; Stdlib. H>
# include & lt; Afxinet. H>
# include "SCHTB. H"
//create a lookup table operation
Void CreatSchTb SeqList (R)
{
Int I;
Int the random (int sum);
//randomize ();
Srand (n);//with the same seed value, initializes the random number generator
for(i=1; I<=n; I++)
R [I] key=random (n * 10);//generate a random number
}
//sorting lookup table, using simple selection sort
Void SortSchTb SeqList (R)
{
Int I, j, k;
for(i=1; IK=I;
For (j=I + 1; J<=n; J++)
If (R [k]. Key> R [j] key) k=j;
If (k! I)={
R [0]=R [I];
R=R [I] [k].
R=R [k] [0];
}
}
}
//sequential search operations
Int SeqSearch (SeqList R, KeyType K)
{
Int I;
R [0]. Key=K;
For (I=n; R [I]. The key!=K; I -);
Return the I;
}
//binary search operations
Int BinSearch (SeqList R, KeyType K)
{
Int low=1, high=n, mid;
While (low & lt;=high) {
Mid=+ high (low)/2;
If (R (mid). The key & lt; K) low=mid + 1;
Else if (R (mid). The key==K) return mid;
The else high=mid - 1;
}
Return 0;
}
//output lookup table data
Void PrtSchTb SeqList (R)
{
Int I;
For (I=1; I<=n; I++)
Printf (" % 4 d ", "R" [I] key);
Printf (" \ n ");
}

//binary sort tree insert
Void InsertBST (BSTree * BT, KeyType key)
{
F BSTNode *, * p=* BT;//f pointing to insert parent node
While (p) {
If (p - & gt; Key==key) return;//with the same keywords, not insert
F=p;
P=(key

}
P=(BSTNode *) malloc (sizeof (BSTNode));
P - & gt; Key=key;
P - & gt; Lchild=p - & gt; Rchild=NULL;
If BT BT (*==NULL) *=p;//if the binary sort tree is empty, it is the root node
The else
If (keyThe else f - & gt; Rchild=p;
}
//create a binary sort tree operations
Void CreatBST (BSTree * TP)
{
Int the random (int sum);
Int I;
* TP=NULL;
Srand (n);
For (I=1; I<=n; I++)
InsertBST (TP, random (n * 10));
}
//binary sort tree find operations
BSTNode * SearchBST (BSTree BT, KeyType key)
{
If (BT==NULL | | BT - & gt; Key==key) return BT;
If (BT - & gt; Key> Key) return SearchBST (BT - & gt; Lchild, key);
The else return SearchBST (BT - & gt; Rchild, key);
}
//the output value of the binary sort tree node operation, with the output sequence traversal
Void PrtBST BSTree (BT)
{
If (BT) {
PrtBST (BT - & gt; Lchild);
Printf (" % 4 d ", BT - & gt; Key);
PrtBST (BT - & gt; Rchild);
}
}
//the current system time
Double GetTime (void)
{
Double T;
CTime t=CTime: : GetCurrentTime ();
Int h=t.G etHour ();//get the current for long
Int mm=t.G etMinute ();//get the current minute
Int s=t.G etSecond ();//get the current second
Int w=t.G etDayOfWeek ();//get week, note 1 for Sunday, 7 for Saturday
Double hund=s/100;
//struct time;
//struct t;
//gettime (& amp; T);
T=(* 60 + mm (h) * 60 + s) * 100 + hund.
Return 0;
}

//main program
Void main (void)
{
SeqList SR, BR.
BSTree BT;
KeyType k [m];
Int I;
Double t1, t2;
Int the random (int sum);

//randomize (); The usage cannot be used in the VC environment, the use of the need to use the following
Srand (time (0));
//have to find data
for(i=0; I[I]=random k (n * 10);
//sequential search algorithm
Printf (" sequential search algorithm for: \ n ");
CreatSchTb (SR);
T1=GetTime ();
for(i=0; I[I] SeqSearch (SR, k);
T2=GetTime ();
Printf (" % d milliseconds \ n ", (int) (t2 - t1));

//binary search algorithmPrintf (" sequential search algorithm for: \ n ");
CreatSchTb (BR);
SortSchTb (BR);
T1=GetTime ();
for(i=0; I[I] BinSearch (BR, k);
T2=GetTime ();
Printf (" % d milliseconds \ n ", (int) (t2 - t1));
//binary sort tree search algorithm
Printf (" binary sort tree search algorithm for: \ n ");
CreatBST (& amp; BT);
T1=GetTime ();
for(i=0; I[I] SearchBST (BT, k);
T2=GetTime ();
Printf (" % d milliseconds \ n ", (int) (t2 - t1));
//PrtBST (BT);
}



SCHTB. H the code in the
//the following is a SCHTB. H header file content,
//the following for sequential search and binary search
# define n/1000/define a lookup table length
# define m/500/definition to find the number of data
Typedef int KeyType;//define the type of keywords
Typedef struct node {//find the node structure defined
KeyType key;
//if the lookup table nodes contain other information, in the add
//infotypes otherinfo;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull

  • Related