当前位置:网站首页>¥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;
}
边栏推荐
猜你喜欢

TCP网络应用程序开发流程

CentOS changes MySQL database directory
![[HCTF 2018]admin](/img/d7/f0155c72d3fbddf0a8c1796a179a0f.png)
[HCTF 2018]admin

『怎么用』装饰者模式

sqli-labs Basic Challenges Less1-10

Uniapp intercepts route jumps through addinterceptor to control whether the page needs to log in

【Nacos】NacosClient在服务注册时做了什么

分享一个避免递归的部门设计方法

Jspdf generates PDF files. There is a problem of incomplete files. Files are downloaded in the background, but not in the foreground

Leetcode组合总和+剪枝
随机推荐
Publish Yum private server using nexus3 (offline intranet)
Mongodb exploration phase [easy to understand]
Common tool classes under JUC package
ActiveMQ -- kahadb of persistent mechanism
MySQL takes the query result as the data updated by update, and concatenates it after the original field data (Lej)
API健康状态自检
一文搞懂为什么要同时重写equals方法和hashCode方法+实例分析
[arm] Xintang nuc977 transplants wk2124 drive
idea中将lib目录下的jar包加入到项目中
sqli-labs Basic Challenges Less11-22
PHP网站设计思路
SSM框架整合,简单案例
sqli-labs安装 环境:ubuntu18 php7
The difference between abstract classes and interfaces (the most detailed)
registration status: 204
What are stand-alone, cluster and distributed?
jsPDF生成PDF文件,文件不全问题,后台进行文件下载,前台不下载
C#语言和SQL Server数据库技术
Numpy- array属性、改变形状函数、基本运算
activemq--异步投递