能帮忙写出这个C++程序每一步的作用或者含义么? 20
#include<iostream>#include<string>usingnamespacestd;structst{stringsno;stringname;int...
#include <iostream>
#include <string>
using namespace std;
struct st
{string sno;
string name;
int score;
st *head;
};
int main()
{st *input();
void print(st *);
st *head;
head=input();
print (head);
st *insertfun(st *);
st *swapfun(st *);
print(insertfun(head));
head=input();
print(swapfun(head));
system("pause");
return 0;
}
st *input()
{st *h,*p,*c;
int n=5;
int i;
for(i=1;i<=n;i++)
{cout<<"输入第"<<i<<"个(结点)学生的数据:";
p=new st;
cin>>p->sno>>p->name>>p->score;
p->next=NULL;
if (i==1) {h=p;c=p;}
else {c->next=p;c=p;}
}
return h;
}
void print(st *p)
{st *h;
h=p;
while (p!=NULL)
{cout<<p->sno<<","<<p->name<<","<<p->score<<endl;
p=p->next;}
}
st *insertfun(st *p)
{st *c,*x,*h=p;
x=new st; x->next=NULL;
cout<<"input insert sno,name,score:";
cin>>x->sno>>x->name>>x->score;
while (p->next!=NULL) {c=p;p=p->next;}
c->next=x;
x->next=p;
return h;
}
st *swapfun(st *p)
{st *c,*h;
c=p;
h=p;p=h->next;
h->next=p->next;
p->next=h;
h=p;
return h;
} 展开
#include <string>
using namespace std;
struct st
{string sno;
string name;
int score;
st *head;
};
int main()
{st *input();
void print(st *);
st *head;
head=input();
print (head);
st *insertfun(st *);
st *swapfun(st *);
print(insertfun(head));
head=input();
print(swapfun(head));
system("pause");
return 0;
}
st *input()
{st *h,*p,*c;
int n=5;
int i;
for(i=1;i<=n;i++)
{cout<<"输入第"<<i<<"个(结点)学生的数据:";
p=new st;
cin>>p->sno>>p->name>>p->score;
p->next=NULL;
if (i==1) {h=p;c=p;}
else {c->next=p;c=p;}
}
return h;
}
void print(st *p)
{st *h;
h=p;
while (p!=NULL)
{cout<<p->sno<<","<<p->name<<","<<p->score<<endl;
p=p->next;}
}
st *insertfun(st *p)
{st *c,*x,*h=p;
x=new st; x->next=NULL;
cout<<"input insert sno,name,score:";
cin>>x->sno>>x->name>>x->score;
while (p->next!=NULL) {c=p;p=p->next;}
c->next=x;
x->next=p;
return h;
}
st *swapfun(st *p)
{st *c,*h;
c=p;
h=p;p=h->next;
h->next=p->next;
p->next=h;
h=p;
return h;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询