?? p1-59.txt
字號:
#include<iostream.h>
main()
{
int i;
//定義名為student的遞歸結構
struct student {
char name[10];
int math;
int computer;
float sum;
student *next; //next成員是指向自身的結構指針
};
//用student聲明3個結構指針變量
struct student *head,*tail,*temp;
//申請第1塊數據,并設置各結構指針的初值
temp=new struct student; //申請內存
head=temp; // 頭指針
tail=head; // 尾指針
//循環為鏈表輸入數據
cout<<"\tname Math Computer"<<endl;
for (i=1;;i++) {
cout<<i<<"\t";
cin>>temp->name;
if (temp->name[0]!='*')
{
cin>>temp->math>>temp->computer;
temp->sum=temp->math+temp->computer;
temp->next=NULL;
tail=temp; //設置鏈表尾指針
}
else
{
// 以下是輸入結束處理
delete temp;
tail->next=NULL;
break;
}
//為下一個學生申請內存
temp->next=new struct student;
temp=temp->next; // 使處理指針temp指向新內存塊
}
//將鏈表數據從頭到尾打印出來
cout<<"--------------------"<<endl;
temp=head;
while (temp!=NULL) {
cout<<temp->name<<","<<temp->math<<",";
cout<<temp->computer<<","<<temp->sum<<endl;
temp=temp->next;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -