📄 10.3.cpp
字号:
#include<iostream.h>
struct node
{
char info;
node* link;
};
int length;
node* CREATE()
{
node* p,*head,*last;
p=new node;
cout<<"输入字符:"<<endl;
cin>>p->info;
head=NULL;
last=p;
while(p->info!='0')
{
if(head==NULL)
head=p;
else
{
last->link=p;
last=p;
}
length++;
cout<<"这是第"<<length<<"个结点"<<endl;
p=new node;
cout<<"输入字符:"<<endl;
cin>>p->info;
}
last->link=NULL;
delete p;
return(head);
}
void SHOW(node* head ,int l)
{
cout<<"下面是相应的链表:"<<endl;
while(l-1)
{
cout<<head->info<<"->";
head=head->link;
l--;
}
cout<<head->info<<"^"<<endl;
}
void INVERT(node* &head)
{
node *p,*q,*r;
p=head;
q=p->link;
while(q!=NULL)
{
r=q->link;
q->link=p;
p=q;
q=r;
}
head->link=NULL;
head=p;
}
void main()
{
node* elf;
cout<<"现在我们来创建一链表"<<endl<<endl;
elf=CREATE();
SHOW(elf,length);
cout<<"逆置..."<<endl;
INVERT(elf);
SHOW(elf,length);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -