当前位置:网站首页>顺序表删除所有值为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);
}
边栏推荐
猜你喜欢
中英文说明书丨CalBioreagents ACTH N端单克隆抗体
ByteDance Written Exam 2020 (Douyin E-commerce)
代码目录结构
工控设备的系统如何进行加固
报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
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
workbench 数据导出
Fragments
leetcode 之 70 爬楼梯问题 (斐波那契数)
线程的6种状态
随机推荐
物理层课后作业
DDD 领域驱动设计
SIGINT, SIGKILL, SIGTERM signal difference, summary of various signals
【Wwise】ArgumentException: The specified path is not of a legal form (empty). About the path reading error in WwiseGlobal
APP商品详情源数据接口(淘宝/京东/拼多多/苏宁/抖音等平台详情数据分析接口)代码对接教程
Error: flask: TypeError: 'function' object is not iterable
简单使用Lambda表达式
leetcode 之盛水问题
jvm线程状态
C语言实现顺序栈和链队列
普罗米修斯原理及节点发布
语句加锁分析
Silently start over, the first page is also a new page
workbench 数据导出
Web APIs BOM- 操作浏览器:本地存储
Go lang1.18入门精炼教程——第一章:环境搭建
SIGINT,SIGKILL,SIGTERM信号区别,各类信号总结
Flask failed to create database without error
TCP segment of a reassembled PDU
字节跳动面试题之镜像二叉树2020