当前位置:网站首页>顺序表删除所有值为e的元素
顺序表删除所有值为e的元素
2022-08-09 06:40:00 【又菜又爱玩呜呜呜~】
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 20
//定义结构体
typedef struct sqlist{
int *data;
int length;
}Sqlist;
//创建线性表
void creatList(Sqlist &L){
//开辟一个大小为 MAXSIZE 的空间
L.data = (int *)malloc(sizeof(int) * MAXSIZE);
//判断开辟是否成功
if (!L.data){
printf("ERROR\n");
} else {
printf("ok\n");
}
printf("please input length\n");
//输入线性表长度
scanf("%d", &L.length);
//循环输入线性表中的值
for (int i = 0 ; i < L.length; i ++){
scanf("%d", &L.data[i]);
}
}
//遍历输出线性表
void TraveList(Sqlist &L){
for (int i = 0 ; i < L.length; i ++){
printf("%2d", L.data[i]);
}
}
//删除表中所有值为e的元素
void deletList(Sqlist &L, int e){
//count计数记录有多少值符合规定
int count = 0;
//如果L中的值不为e则将其放入线性表中,负责不录入
for (int i = 0 ; i < L.length ; i ++){
if (L.data[i] != e){
L.data[count ++] = L.data[i];
}
}
//将表长变为count,表示未被删除的所有元素的个数
L.length = count;
}
int main(){
Sqlist L;
int n;
creatList(L);
TraveList(L);
printf("\n");
printf("what do you want delet?\n");
scanf("%d", &n);
deletList(L,n);
printf("\n");
TraveList(L);
}
边栏推荐
- 中英文说明书丨TRC 交替醇(Catalogue NumberA575760)
- Redis 2 - 高级
- Zero shift of leetcode
- APP商品详情源数据接口(淘宝/京东/拼多多/苏宁/抖音等平台详情数据分析接口)代码对接教程
- 中英文说明书丨CalBioreagents 醛固酮单克隆抗体
- 找出数组中不重复的值php
- codeforces Valera and Elections (这思维题是做不明白了)
- 细谈VR全景:数字营销时代的宠儿
- C语言的内置宏(定义日志宏)
- Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
猜你喜欢

leetcode 之 70 爬楼梯问题 (斐波那契数)

Fragments

static静态关键字和继承

2022-08-08: Given an array arr, it represents the height of the missiles that will appear in order from morning to night.When the cannon shoots missiles, once the cannon is set to shoot at a certain h

推进产教融合 赋能教育创新发展 | 华云数据荣获“企业贡献奖”

CMake中INSTALL_RPATH与BUILD_RPATH问题

Error jinja2.exceptions.UndefinedError: 'form' is undefined

Flask failed to create database without error

普罗米修斯原理及节点发布

当酷雷曼VR直播遇上视频号,会摩擦出怎样的火花?
随机推荐
mmdetection源码解析--ResNet18
事务总结
细谈VR全景:数字营销时代的宠儿
The working principle of the transformer (illustration, schematic explanation, understand at a glance)
工控设备的系统如何进行加固
2017.10.26模拟 b energy
The Integer thread safe
The water problem of leetcode
SIGINT,SIGKILL,SIGTERM信号区别,各类信号总结
逆向工程
leetcode 之盛水问题
Redis 2 - 高级
static静态关键字和继承
golang xml 处理动态属性
DDD 领域驱动设计
mongo+ycsb性能测试及线程数分析
String.toLowerCase(Locale.ROOT)
bzoj 5333 [Sdoi2018]荣誉称号
golang zip aes base64
CMake中INSTALL_RPATH与BUILD_RPATH问题