c++要怎么写代码运行

img

代码如下,如有帮助,请帮忙采纳一下,谢谢。


#include <iostream>
using namespace std;
struct StNode 
{
    int id;
    int score;
    struct StNode* next;
};

int main()
{
    struct StNode* head,*p,*t;
    int i;
    head = 0;
    for (i=0;i<3;i++)
    {
        p = new struct StNode;
        cin >> p->id >> p->score;
        p->next = 0;
        if (head == 0)
        {
            head = p;
            t = head;
        }else
        {
            t->next = p;
            t = p;
        }
    }

    //显示
    t = head;
    while (t)
    {
        cout << "[num=" << t->id << ",score=" << t->score <<"]"<<endl;
        t = t->next;
    }

    //释放空间
    while(head)
    {
        t= head->next;
        delete head;
        head = t;
    }
    head = 0;
    return 0;
    
}