zoukankan      html  css  js  c++  java
  • 第六次作业

    看视频的笔记


    1.视频中出现的typedef书上的链表里没有,它的意思为:

    用了它方便书写


    2

    这个if语句不太懂

    通过这次的讲解,我已经基本掌握它的意思


    3.视频中链表函数的几种方法也不大懂它的意思


    4.

    这块也不是很明白


    手写笔记


    代码(大致流程)

     先从静态链表开始理解:

     1 #include<stdio.h>
     2 #include<string.h>
     3 struct stud_node{
     4     int num;
     5     char name[20];
     6     int score;
     7     struct stud_node*next;
     8 }; 
     9     //静态链表 
    10 int main(){
    11     
    12     //创建结点
    13     struct stud_node a,b,c;
    14     a.num=1;strcpy(a.name,"djsioj");a.score=85; a.next=NULL;
    15     b.num=2;strcpy(b.name,"dncyud");b.score=88; b.next=NULL;
    16     c.num=3;strcpy(c.name,"udhccj");c.score=83; c.next=NULL;
    17     
    18     //链接结点
    19     struct stud_node*head=NULL;
    20     head=&a;
    21     a.next=&b;
    22     b.next=&c;
    23     c.next=NULL;
    24     
    25     //打印输出各个结点中的数据
    26     struct stud_node*p=NULL;
    27     for(p=head;p!=NULL;p=p->next) 
    28     printf("%d %s %d
    ",p->num,p->name,p->score);
    29     
    30     return 0; 
    31 }

    然后再理解动态链表

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 struct stud_node{
     5     int num;
     6     char name[20];
     7     int score;
     8     struct stud_node*next;
     9 }; 
    10 int main()
    11 {
    12 
    13     
    14     struct stud_node*p=NULL,*head=NULL,*tail=NULL; 
    15     int number;
    16     
    17         //1.创建结点
    18     p=(struct stud_node*)malloc(sizeof(struct stud_node));
    19     scanf("%d",&(p->num));
    20     scanf("%s",p->name);
    21     scanf("%d",&(p->score));
    22     
    23     
    24 
    25     //2.链接结点 要么链接到头 要么到尾 
    26     if(head=NULL){
    27         head=p;
    28         p->next=NULL;
    29         tail=p; 
    30     }
    31     else{
    32         tail->next=p;
    33         p->next=NULL;
    34         tail=p;
    35     }
    36 
    37     //3.打印输出各个结点中的数据
    38     struct stud_node*q=NULL;
    39     for(q=head;q!=NULL;q=q->next){
    40         printf("%d %s %d",q->num,q->name,q->score);
    41     }
    42 
    43      return 0;
    44 }

     

    文件


    1.以“a”方式打开一个文件时,文件指针指向文件首。
    (错误)
    解析:文件打开时,原有文件内容不被删除,位置指针移到文件末尾,可以进行添加或读操作

     

    2.“a+"方式:以附加方式打开可读/写的文件。若文件不存在,则会建立该文件,如果文件存在,则写入的数据会被加到文件尾后,即文件原先的内容会被保留(原来的EOF符 不保留) 文件打开时,原有文件内容不被删除,位置指针移到文件末尾,可作添加和读操作


     

  • 相关阅读:
    iOS初级博客的链接
    代理参数问题的思考
    数组里面的选择排序与起泡排序比较
    【C语言】02-函数
    【C语言】01-第一个c程序代码分析
    响应者链的事件分发
    UIController中view的记载流程
    UITabBar的定制
    CommandTabel_代理方法
    来到博客园
  • 原文地址:https://www.cnblogs.com/lcy2001/p/12778673.html
Copyright © 2011-2022 走看看