SDUT顺序表系列

本文介绍了一个使用C++实现的数据结构操作示例,包括初始化、创建、打印、删除重复项、反转数组等基本功能,并展示了如何通过哈希表进行元素搜索。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include<bits/stdc++.h>
using namespace std;
bool hash[20050];
int hashs[20050];
struct node
{
    int *h,lt,ls;
};
void intl(struct node *l)
{
    l->h=(int *)malloc(10050*sizeof(int));
    l->lt=0;
    l->ls=10050;
}
void creat(struct node *l,int k)
{
    for(int i=0; i<k; i++)
        scanf("%d",&l->h[i]);
    l->lt=k;
}
void print(struct node *l)
{
    for(int i=0; i<l->lt; i++)
        printf("%d ",l->h[i]);
}
void del(struct node *l)//SDUT3324&&1130
{
    for(int *p=l->h; p<l->h+l->lt; p++)
        for(int *q=p+1; q<l->h+l->lt; q++)
            if(*p==*q)
            {
                for(int *r=q; r<l->h+l->lt; r++)
                    *r=*(r+1);
                l->lt--;
                q--;
            }


}
void rev(struct node *l,int m)//SDUT3329
{
    reverse(l->h,l->h+m);
    reverse(l->h+m,l->h+l->lt);
    reverse(l->h,l->h+l->lt);


}
void hashprint(struct node *l)//SDUT3325
{
    memset(hash,false,sizeof(hash));
    for(int i=0; i<l->lt; i++)
    {
        if(!hash[l->h[i]])
            printf("%d ",l->h[i]);
        hash[l->h[i]]=true;
    }
}
void mergerprint(struct node *l1,struct node *l2,int m,int n)//SDUT3329
{
    int i,j;
    for(i=0,j=0; i<m&&j<n;)
        if(l1->h[i]<l2->h[j])
        {
            printf("%d ",l1->h[i]);
            i++;
        }
        else
        {
            printf("%d ",l2->h[j]);
            j++;
        }
    for(int k=i; k<m; k++)
        printf("%d ",l1->h[k]);
    for(int k=j; k<n; k++)
        printf("%d ",l2->h[k]);
}
void hashcreat(struct node *l,int k)
{
    memset(hashs,0,sizeof(hashs));
    for(int i=1; i<=k; i++)
    {
        scanf("%d",&l->h[i]);
        hashs[l->h[i]]=i;
    }
    l->lt=k;
}
void hashsearch(int l)
{
    if(hashs[l])
        printf("%d\n",hashs[l]);
    else
        printf("No Found!\n");
}
int main()
{
    int n;
    scanf("%d",&n);
    struct node l;
    intl(&l);
    hashcreat(&l,n);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int t;
        scanf("%d",&t);
        hashsearch(t);
    }


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值