首页 > 其他 > 详细

考试题目

时间:2014-03-22 05:46:47      阅读:371      评论:0      收藏:0      [点我收藏+]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#define _CRT_SECURE_NO_DEPRECATE
 
 
#include "stdio.h"
#include "stdlib.h"
#include "conio.h"
 
 
typedef struct linked_list linked_list;
struct linked_list{
    int num;
    linked_list * next;
};
 
 
linked_list list = { 0, NULL };
int count = 0;
 
void display(){
    linked_list * p = list.next;
    int i = 0;
 
    puts( "列表输出:" );
    while( p != NULL ){
        printf( "%d: %d\n", i, p->num );
        p = p->next;
        i++;
    }
 
    puts( "输入次数:" );
    printf( "%d\n", count );
 
    _getch();
}
 
void input(){
    linked_list * p = &list;
    linked_list * tmp = NULL;
    int n;
 
    printf( "请输入数字:" );
    scanf( "%d", &n );
 
    tmp = ( linked_list * )malloc( sizeof( linked_list ) );
    tmp->num = n;
    tmp->next = NULL;
 
    while( NULL != p->next ){
 
        if( p->next->num > n ){
 
            tmp->next = p->next;
 
            p->next = tmp;
 
            count++;
             
            return;
        }
 
        p = p->next;
    }
 
    p->next = tmp;
 
    count++;
}
 
void delnum(){
    linked_list * p = &list;
    linked_list * tmp = NULL;
    int id = 0;
    int i;
 
    if( NULL == list.next ){
        return;
    }
 
    printf( "请输入数字ID:" );
    scanf( "%d", &id );
 
    for( i = 0; i < id; i++ ){
        p = p->next;
 
        if( NULL == p->next ){
            return;
        }
    }
 
    tmp = p->next;
    p->next = p->next->next;
 
    free( tmp );
}
 
void average(){
    linked_list * p = list.next;
    int sum = 0;
    int i = 0;
 
    if( NULL == list.next ){
        return;
    }
 
    while( NULL != p ){
        sum += p->num;
        i++;
        p = p->next;
    }
 
    puts( "平均数为:" );
    printf( "%d\n",sum / i );
 
    _getch();
}
 
void maxnum(){
    linked_list * p = NULL;
    int max;
 
    if( NULL == list.next ){
        return;
    }
    else{
        max = list.next->num;
    }
 
    p = list.next->next;
 
    while( NULL != p ){
        if( p->num > max ){
            max = p->num;
        }
 
        p = p->next;
    }
 
    puts( "最大数为:" );
    printf( "%d\n",max );
 
    _getch();
}
 
void minnum(){
    linked_list * p = NULL;
    int min;
 
    if( NULL == list.next ){
        return;
    }
    else{
        min = list.next->num;
    }
 
    p = list.next->next;
 
    while( NULL != p ){
        if( p->num < min ){
            min = p->num;
        }
 
        p = p->next;
    }
 
    puts( "最小数为:" );
    printf( "%d\n",min );
 
    _getch();
}
 
void menu(){
    int key = ‘\0‘;
 
    while( key != ‘0‘ ){
        system( "cls" );
        puts( "1.列表输出" );
        puts( "2.输入" );
        puts( "3.删除" );
        puts( "4.平均值" );
        puts( "5.最大值" );
        puts( "6.最小值" );
        puts( "0.退出" );
 
        key = _getch();
 
        switch( key ){
        case ‘1‘:{
            display();
                 }break;
        case ‘2‘:{
            input();
                 }break;
        case ‘3‘:{
            delnum();
                 }break;
        case ‘4‘:{
            average();
                 }break;
        case ‘5‘:{
            maxnum();
                 }break;
        case ‘6‘:{
            minnum();
                 }break;
        }
    }
}
 
int main(){
 
    menu();
 
    return 0;
}

  

考试题目,布布扣,bubuko.com

考试题目

原文:http://www.cnblogs.com/wrule/p/3616090.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!