急急急!请大家指点一下啊!谢了!
怎样修改Srand,加上随机数存储目的的指针 或者 分配足够空间存储随机数反回地址外面释放空间.才能使我的程序能够调用不同的随机函数进行查找!请修改一下吧!
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define NULL 0
#define keytype int
typedef struct node
{
keytype data;
struct node *next;
}NodeType;
int Srand()
{
int i;
int value;
srand((unsigned)time(NULL));
value = rand();
printf("%d\n",value);
return value;
}
NodeType *HeadCreate()
{
NodeType *head=NULL,*t;
int i, max;
scanf("%d\n",&max);
head=(NodeType *)malloc(sizeof(NodeType));
head->data=Srand();
t=head;
for (i=0;i<max;++i)
{
t->next=(NodeType *)malloc(sizeof(NodeType));
t->next->data=Srand();
t=t->next;
t->next=NULL;
}
return head;
}
NodeType *Seq_search(NodeType *head,keytype k)
{
NodeType *p=p->next;
while(p!=NULL&&p->data!=k)
p=p->next;
return p;
}
int main(void)
{
NodeType *la=NULL;
NodeType *p;
int k;
scanf("%d\n",&k);
la=HeadCreate();
p=Seq_search(la,k);
if(p!=NULL)
printf("Find!The Locatin is:%x,It's data is d\n",p,p->data);
else
printf("Sorry,can't find!");
return 0;
}