第13周 补充阅读-链表类1

#include <iostream>
using namespace std;
struct Student
{
    int num;
    double score;
    struct Student *next;
};
int main( )
{
    Student *head=NULL,*p,*q;
    //建立动态链表
    for(int i=0; i<3; i++)
    {
        p = new Student;
        cin>>p->num>>p->score;
        p->next=NULL;
        if (i==0) head=p;
        else q->next=p;
        q=p;
    }
    //输出动态链表
    p=head;
    while(p!=NULL)
    {
        cout<<p->num<<" "<<p->score<<endl;
        p=p->next;
    }
    return 0;
}

运行结果:

时间: 2024-08-22 01:03:14

第13周 补充阅读-链表类1的相关文章

第13周 【项目 - 链表类】(2)

(2)请在下面已有代码的基础上完善程序,完成动态链表的简单操作,程序运行的截图供参考. class Student //结点类 { public: Student(int n,double s):num(n), score(s), next(NULL) {} ~Student(); Student *next; //指向下一个结点 int num; double score; }; class MyList //链表类,其中的成员是学生 { public: MyList() { head=NUL

16周 补充阅读

问题描述: 补充阅读 <code class="hljs cpp has-numbering"><span style="font-family:KaiTi_GB2312;font-size:18px;color:#ff6666;"><strong><span class="hljs-preprocessor">#include <iostream></span> <s

第九周 程序阅读-字符串类的设计

阅读下面的程序,领会其中用到的设计方案.技术手段与算法. /* 对于要定义的字符串类CMyString, 数据成员包括: - 字符串的长度: - 指向字符串第一个字符的指针 成员函数包括: - 不带参数的构造函数: - 带一个类型为const char *类型的参数(用于对字符串初始化)的构造函数: - 带一个const CMyString&类型的复制构造参数: - 析构函数: - Strlen函数 (用于求字符串的长度): - int Find(char c) (找出字符c在本字符串中第一次出

第12周 补充阅读

#include <iostream> using namespace std; class B { public: B(int x=0) { X=x; cout<<"B("<<x<<")\n"; } ~B() { cout<<"~B()\n"; } void print() { cout <<X<< " "; } private: int X

第13周 程序阅读-虚析构函数

#include <iostream> using namespace std; class BASE { private: char c; public: BASE(char n):c(n) {} virtual ~BASE() { cout<<c; } }; class DERIVED:public BASE { private: char c; public: DERIVED(char n):BASE(n+1),c(n) {} ~DERIVED(){ cout<<

第13周 程序阅读-虚函数

#include<iostream> using namespace std; class A { int a; public: A():a(5){} virtual void print()const { cout<<a;} }; class B: public A { char b; public: B() { b='E'; } void print() const { cout<<b; } }; void show(A &x) { x.print(); }

第13周 程序阅读-纯虚函数

#include <iostream> using namespace std; class Base { public: virtual void Who() =0; }; class FirstDerived:public Base { public: void Who() { cout<<"F"; } }; class SecondDerived:public Base { public: void Who() { cout<<"S&

20145239 《信息安全系统设计基础》第13周学习总结

20145239 <信息安全系统设计基础>第13周学习总结 本周代码实践 hello_multi.c 先打印world换行打印hello,间隔1秒再打印相同内容,一共打印5次,最后输出t1,t2 finished hello_multi1.c hello_single.c 打印一个hello,之后每间隔1秒打印一 个hello,共5个:然后打印一个world并换行,之后每间隔1秒打印一个world,共5个 incprint.c 在屏幕上换行输出count=1,2,3,4,5,间隔1秒 twor

单链表类模板

单链表类模板节点头 ListNode.h 1 #include "stdafx.h" 2 #include<iostream> 3 using namespace std ; 4 template<typename Type> class SingleList; 5 template <typename Type> 6 class ListNode{ 7 private: 8 friend class SingleList<Type>;