当前位置:网站首页>¥1-3 SWUST oj 942: 逆置顺序表
¥1-3 SWUST oj 942: 逆置顺序表
2022-07-25 09:19:00 【叶萧白】
题目描述

源代码
#include<iostream>
#include<stdlib.h>
#include<malloc.h>
using namespace std;
typedef char ElemType;
class SqList
{
public:
ElemType data[100];
int length;
};
void CreateList(SqList *&L,ElemType a[],int n)//创建顺序表
{
int i=0,k=0;
L=(SqList *)malloc(sizeof(SqList));
while(i<n)
{
L->data[k]=a[i];
k++;i++;
}
L->length=k;
}
void InitList(SqList *&L)//初始化
{
L=(SqList *)malloc(sizeof(SqList));
L->length=0;
}
void Inverse(SqList *&L)//逆置顺序表
{
int i=0,k=L->length-1;
ElemType a[100];
while(i<L->length)
{
a[i]=L->data[k];
i++;k--;
}
i=0;
while(i<L->length)
{
L->data[i]=a[i];
i++;
}
}
void ShowList(SqList *L)
{
for(int i=0;i<L->length;i++)
{
if(i!=L->length)
{
cout<<L->data[i]<<" ";
}else
{
cout<<L->data[i];
}
}
}
int main()
{
int n;
ElemType a[100];
SqList *L;
cin>>n;
getchar();
for(int i=0;i<n;i++)
{
cin>>a[i];
}
CreateList(L,a,n);
Inverse(L);
ShowList(L);
return 0;
}
边栏推荐
- [GYCTF2020]Ez_Express
- Go基础2
- CentOS changes MySQL database directory
- Jspdf generates PDF files. There is a problem of incomplete files. Files are downloaded in the background, but not in the foreground
- Ranking of data results in MySQL
- 实现简单的RESTful API服务器
- redis的五种数据结构原理分析
- uni-app - Refused to display ‘xxx‘ in a frame because an ancestor violates the following Content Sec
- Redis安装(Ubuntu)
- 数据控制语言(DCL)
猜你喜欢

什么是单机、集群与分布式?

Do you know these methods of MySQL database optimization?

Idea practical tips --- now change pom.xml (red) to pom.xml (blue)
![[GKCTF 2021]easynode](/img/f0/1daf6f83fea66fdefd55608cbddac6.png)
[GKCTF 2021]easynode

Redis安装(Ubuntu)

『怎么用』代理模式

数据查询语言(DQL)

Leetcode组合总和+剪枝

ActiveMQ -- JDBC Journal of persistent mechanism
![[C language] dynamic memory management, flexible array](/img/da/b9455885df0cb6646908e3655d62c5.png)
[C language] dynamic memory management, flexible array
随机推荐
MySQL的索引、视图与事务
Do you know these methods of MySQL database optimization?
PHP date() function does not support processing numbers greater than 2147483648? "Suggested collection"
sqli-labs Basic Challenges Less1-10
ActiveMQ -- persistent mechanism
What is anemia model and congestion model?
Numpy - 数组array的构造
@Scheduled源码解析
[GYCTF2020]Node Game
『怎么用』代理模式
ActiveMQ -- JDBC Journal of persistent mechanism
【线程知识点】-- 自旋锁
Nacos搭建配置中心出现client error: invalid param. endpoint is blank
excl批量导入数据,后台公共解析方法
『每日一问』LockSupport怎么实现线程等待、唤醒
【Nacos】NacosClient在服务注册时做了什么
OmniPeek packet capturing tool
activemq--异步投递
ActiveMQ -- kahadb of persistent mechanism
神经网络方法——美国波士顿房价(回归问题)