📄 main.cpp
字号:
#include <iostream.h>
#include <stdlib.h>
struct num
{
int data;
num *next;
};
void main()
{
num *head=NULL, *tail=NULL, *temp=NULL;
head=new num;
tail=head;
cout << "请输入:" << endl;
for(int i=1; i<10; i++)
{
int x;
cin >> x;
temp=new num;
temp->data=x;
tail->next=temp;
tail=temp;
}
tail->next=NULL;
temp=head->next;
int max=temp->data;
while(temp!=NULL)
{
cout << temp->data << "\t";
if(temp->next!=NULL) //后继结点有可能为空,需先判断是否存在
if(max<temp->next->data)
max=temp->next->data;
temp=temp->next;
}
bool flag=false;
do
{
flag=false;
num *p1, *p2;
p1=head;
while(p1->next!=NULL && p1->next->data!=max) //先判断后继结点存在否,若不存在就不会再
//判断p1->next->data!=max了
{
p1=p1->next;
}
if(p1->next!=NULL)
{
flag=true;
p2=p1->next;
p1->next=p2->next;
delete p2;
}
}while(flag==true);
cout << "\n删除最大结点后:"<<endl;
temp=head->next;
while(temp!=NULL)
{
cout << temp->data << "\t";
temp=temp->next;
}
cout << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -