zoukankan      html  css  js  c++  java
  • 链表学习

    细细理解

     1 #include <stdio.h>
     2 #include <iostream>
     3 #include <string>
     4 #include <string.h>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <stdlib.h>
     8 using namespace std;
     9 struct film{
    10     char title[45];
    11     int rating;
    12     struct film * next;
    13 };
    14 int main()
    15 {
    16     struct film * head = NULL;
    17     struct film * prev, * current;
    18     char input[45];
    19     
    20     puts("enter first movie title: ");
    21     while(gets(input) != NULL && input[0] != ''){
    22         current = (struct film *)malloc(sizeof(struct film));
    23         if(head == NULL)
    24            head = current;
    25         else
    26            prev->next = current;
    27         current->next = NULL;    
    28         strcpy(current->title,input);
    29         puts("rating : ");
    30         scanf("%d",&current->rating);
    31         while(getchar() != '
    ')
    32            continue;
    33         puts("enter next movie title : ");
    34         prev = current;
    35     }
    36     if(head == NULL)
    37        printf("NO data entered.");
    38     else
    39        printf("Here is the movie list: 
    ");
    40     current = head;
    41     while (current != NULL)
    42     {
    43         printf("Movie: %s Rsting: %d
    ",current->title,current->rating);
    44         current = current->next;
    45     }
    46     current = head;
    47     while (current != NULL)
    48     {
    49         free(current);
    50         current = current->next;
    51     }
    52     printf("Bye!
    ");
    53     return 0;
    54 }
  • 相关阅读:
    CentOS安装gotop
    oracle 非sys用户创建新用户 授权后 plsql看不到视图
    解决Eclipse+ADT连接夜神模拟器失败问题
    Ext JS v2.3.0 Ext.grid.ColumnModel renderer Record 获取列值
    vi常用快捷键汇总
    外键的变种
    完整性约束
    数据类型2
    数据类型
    表的操作
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/4664249.html
Copyright © 2011-2022 走看看