2021-01-29

线性表的几道题:
一逆序:
#include<stdio.h>
#include<stdlib.h>

int min(int num);

int main()
{
int i,j,k,num;
scanf("%d",&num);
i=min(num);
printf("%d",i);
return 0;
}

int min(int num)
{
struct arr
{
int value;
struct arr* next;
}*head,p;
head=NULL;
int MIN=999999999;
for(int a=0;a<num;a++)
{
p=(struct arr
)malloc(sizeof(struct arr));
scanf("%d",&p->value);
if(head==NULL)
{
head=p;
head->next=NULL;
}
else
head->next=p;
head=p;
if(MIN>p->value)MIN=p->value;
}
return MIN;
}

二MIN:
#include<stdio.h>
#include<stdlib.h>

int min(int num);

int main()
{
int i,j,k,num;
scanf("%d",&num);
i=min(num);
printf("%d",i);
return 0;
}

int min(int num)
{
struct arr
{
int value;
struct arr* next;
}head,p;
head=NULL;
int MIN=999999999;
for(int a=0;a<num;a++)
{
p=(struct arr
)malloc(sizeof(struct arr));
scanf("%d",&p->value);
if(head==NULL)
{
head=p;
head->next=NULL;
}
else
head->next=p;
head=p;
if(MIN>p->value)MIN=p->value;
}
return MIN;
}
3,去重
#include<stdio.h>
#include<stdlib.h>
struct arr
{
int value;
struct arr
next;
};
int K;
int find(struct arr* head,int value)
{
if(head->valuevalue)
return -1;
while(head->next!=NULL)
{
if(head->value
value)
return -1;
else ;
head=head->next;
}
return 1;

}
struct arr* creat(struct arr* head,int num)
{
K=0;
int suffer;
struct arr* p;
p=(struct arr*)malloc(sizeof(struct arr));
scanf("%d",&p->value);
p->next=head;
head=p;
for(int a=0; a<num-1; a++)
{
p=(struct arr*)malloc(sizeof(struct arr));
scanf("%d",&p->value);
if(find(head,p->value)==1)
{
p->next=head;
K++;
head=p;
}
}
return head;
}
void print(struct arr* head)
{
// printf("%d “,&head->value);
int arr[1000];
int tail=0;
for(int a=0; a<=K; a++)
{
arr[tail]=head->value;
tail++;// printf(”%d “,head->value);
head=head->next;
}
if(tail>0)tail–;
for(;tail>=0;tail–)
printf(”%d ",arr[tail]);
}

int main()
{
struct arr* head=NULL;
int num;
scanf("%d",&num);
head=creat(head,num);
print(head);
}
》》》对3,有几点注意:
A:可以先储存,在去重
也可以读一个检验一下
B:这里(3题都是)是一个栈结构,线性表也可以是队列的
C:在struct arr{
int value;
struct arr* next;
}head;
head->next=NULL(错)
head=NULL(对)中

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值