zzy周一作业

zzy.c

#include<stdio.h>
#include<stdlib.h>
#include"hash.h"

void has(node *hash[])
{
    for(int i=0;i<p;i++)
    {
        hash[i]=NULL;
    }
    printf("初始化才成功");
}


int insert(node *hash[],int x)
{
    int index =x%p;
    node *q=(node*)malloc(sizeof(node));
    if(q==NULL)
    {
        printf("空间申请失败\n");
        return -1;
    }
    q->data=x;
    q->next=NULL;
    //使用头插法将节点放入表中//
    q->next=hash[index];
    hash[index]=q;
    return 0;
}

void show(node *hash[])
{
for(int i=0;i<p;i++)
    {
        printf("%d",i);
        node *q=hash[i]; //定义遍历指针//
        while(q!=NULL)
        {
            printf("%d->",q->data);
            q=q->next;
        }
        printf("NULL\n");
    }
}
void search(node *hash[],int key)
{
    int index=key%p;  //定义要查找的值//
    //定义遍历指针遍历列表//
    node *q=hash[index];
    while(q!=NULL && q->data!=key)
    {
        q->next;
    }
    if(NULL==q)
    {
        printf("查找失败\n");
    }else
    {
        printf("您查找的数据在表中");
    }
}

zzy2.c

#include<stdio.h>
#include<stdlib.h>
#include"hash.h"

void has(node *hash[])
{
    for(int i=0;i<p;i++)
    {
        hash[i]=NULL;
    }
    printf("初始化才成功");
}


int insert(node *hash[],int x)
{
    int index =x%p;
    node *q=(node*)malloc(sizeof(node));
    if(q==NULL)
    {
        printf("空间申请失败\n");
        return -1;
    }
    q->data=x;
    q->next=NULL;
    //使用头插法将节点放入表中//
    q->next=hash[index];
    hash[index]=q;
    return 0;
}

void show(node *hash[])
{
for(int i=0;i<p;i++)
    {
        printf("%d",i);
        node *q=hash[i]; //定义遍历指针//
        while(q!=NULL)
        {
            printf("%d->",q->data);
            q=q->next;
        }
        printf("NULL\n");
    }
}
void search(node *hash[],int key)
{
    int index=key%p;  //定义要查找的值//
    //定义遍历指针遍历列表//
    node *q=hash[index];
    while(q!=NULL && q->data!=key)
    {
        q->next;
    }
    if(NULL==q)
    {
        printf("查找失败\n");
    }else
    {
        printf("您查找的数据在表中");
    }
}

 hash.h

#include<stdio.h>
#include<stdlib.h>
#include"hash.h"

void has(node *hash[])
{
    for(int i=0;i<p;i++)
    {
        hash[i]=NULL;
    }
    printf("初始化才成功");
}


int insert(node *hash[],int x)
{
    int index =x%p;
    node *q=(node*)malloc(sizeof(node));
    if(q==NULL)
    {
        printf("空间申请失败\n");
        return -1;
    }
    q->data=x;
    q->next=NULL;
    //使用头插法将节点放入表中//
    q->next=hash[index];
    hash[index]=q;
    return 0;
}

void show(node *hash[])
{
for(int i=0;i<p;i++)
    {
        printf("%d",i);
        node *q=hash[i]; //定义遍历指针//
        while(q!=NULL)
        {
            printf("%d->",q->data);
            q=q->next;
        }
        printf("NULL\n");
    }
}
void search(node *hash[],int key)
{
    int index=key%p;  //定义要查找的值//
    //定义遍历指针遍历列表//
    node *q=hash[index];
    while(q!=NULL && q->data!=key)
    {
        q->next;
    }
    if(NULL==q)
    {
        printf("查找失败\n");
    }else
    {
        printf("您查找的数据在表中");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值