📄 链表转置.cpp
字号:
#include<iostream>
using namespace std;
#include<stdlib.h>
struct Lnode
{
int data;
Lnode *next;
};
Lnode *CreateList(int n)//创建链表
{
int a,i;
Lnode *h,*p;
h=NULL;
cout<<"输入元素:";
for(i=0;i<n;i++)
{
cin>>a;
p=new Lnode;
p->data=a;//输入的数赋给链表
p->next=h;
h=p; //转置
}
return h;
}
void put_out(Lnode *h) //输出函数
{
Lnode *p=h;
while(p!=NULL)
p=p->next;
p=h;
cout<<"转置结果:";
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
cout<<endl;
}
void main()
{
Lnode *p,*q;
int n;
cout<<"输入元素的个数:";
cin>>n;
p=CreateList(n);
q=p;
put_out(p);
system("pause");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -