逆置线性表(线性表)

)时间限制: 1 Sec  内存限制: 128 MB
提交: 279  解决: 158
[提交][状态][讨论版]

题目描述

(线性表)请写一个算法将顺序存储结构的线性表(a1...an)逆置为(an...a1)。

输入

输入长度n:5

输入数据:1 2 3 4 5

输出

5 4 3 2 1

样例输入

5
7 8 9 10 11 

样例输出

11 10 9 8 7 
#include<iostream>
using namespace std;
struct mm
{int a;
mm *s;
};
int main()
{int n;
mm *p,*h;
p=new mm;
p->s=NULL;
cin>>n;
 while(n--)
 { 
 cin>>p->a;
h=new mm;
h->s=p;
p=h;
 }
 int i=1;
 p=p->s;
 while(p!=NULL)
 {
	 cout<<p->a<<' ';
 p=p->s;
 }
cout<<endl;
return 0;
}

原文地址:https://www.cnblogs.com/oversea201405/p/3767018.html