TASK(结点插入)

01#include <iostream>
02using namespace std;
03int s;
04struct student
05{
06    int Order;
07    char  Name[10];
08    char Sex[2];
09    int Grade;
10} temp;
11struct node
12{
13    struct student data;
14    struct node *next;
15}*head;
16void inserrt(struct node *head,int a,struct student b)
17{
18    struct node *p,*q;
19    p=head;
20    for(int i=0; i<a&&i<s; i++)
21        p=p->next;
22    q=new node;
23    q->data=b;
24    q->next=p->next;
25    p->next=q;
26    s++;
27}
28void show (struct node*head)
29{
30    struct node*p=head->next;
31    while(p)
32    {
33        cout<<p->data.Order<<" "<<p->data.Name<<" "<<p->data.Sex<<" "<<p->data.Grade<<endl;
34        p=p->next;
35    }
36}
37int main()
38{
39    int a;
40    s=0;
41    head=new node;
42    head->next=NULL;
43    while(cin>>a&&a!=-1)
44    {
45        cin>>temp.Order>>temp.Name>>temp.Sex>>temp.Grade;
46        inserrt(head,a,temp);
47    }
48    show(head);
49    return 0;
50}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值