|
|

楼主 |
发表于 2005-3-31 02:09:19
|
显示全部楼层
前几天看完啦折大的c因为忙于看数据结构就忘啦点评完.下面接着点评+ |) B3 `/ ] T, z$ N
对于指针课程分的很详细讲有下面的例子是指针数组
, E8 I% I6 ~. q#include<stdio.h>7 s* T& n' Z9 h
void main()
- {" D' U/ H( M3 e5 U9 J{7 e6 ^ Q+ v% D/ |1 r/ v# ]
char *name[4]={"wang","li","zhao",jin"};# Y, K# H; w& q6 B w
char **pp;1 f0 x/ ?8 u8 e/ U2 M+ y4 h
for(pp=name;pp<name+4;pp++)3 ]: S- G6 D; i4 e$ b d( ^. }
printf("%c",**pp+1);2 D7 U0 B, n7 G9 l4 Z. O: r
}* ~$ _- S! P0 E: f' @! P& A3 v
但我唯一觉得不足的是数组指针的例子太少可能和课时太少有关吧!对于链表我认为是讲的最好的部分在该课程中从算法到流程及最后的程序书写下面给出链表的一个例子:. Q3 Z$ N& O% z4 g
#include "stdio.h"
8 c& m6 C. \' t: D% @9 {9 S: jstruct student{
" O. S' Z+ ?" i6 g+ h# \int num;, t. Z4 U9 P: g, W0 r
float score;; R. \8 [% V" i' W; M p, W8 N
struct student *next;) x6 S2 q/ ] S/ {! f; b; `4 t
};1 @" c* u" ?' X2 n2 W
struct student *creat();
1 V4 \4 \8 B; A. B: w& C3 p7 O6 ~main()
Z# Y- M# h3 C1 W{
+ l6 c* a" e/ \struct student *head;) W h9 Q( v0 d
head=creat();
+ h7 s4 z; @/ K, a9 l}: M5 L; f; b( M( a/ s+ ^: o
struct student *creat()
6 x5 \. W4 K5 u; g' I$ e{struct student *head,*tail,*p;float score;
. O( |: @( C* d" `int num,size=sizeof(struct student); g* k: I$ U. g) X
head=tail=NULL; }" k" R, H6 {7 m0 B
scanf(%d%f",&num,&score);( m$ S6 \% u- z Z. l* w* y
while(num){5 `1 e. B" K0 h( S T" Y4 h
p=(stuct student *)malloc(size);
, w7 }$ b7 v0 D- Cp->num=num;p->score=score;0 p6 B+ n6 m1 c# @ O
p->next=NULL;
2 l, E( X/ a( R' ?3 tif(head==NULL)head=p;7 L+ N4 _: Y% q9 M
else tail->next=p;: E9 e* g2 t( C6 V
tail=p;
: d/ U$ \- P7 O+ g# i c. T7 wscanf("%d%f",&num,&score);
$ R+ Y, E# p8 L W$ H6 h" q* P9 v}
/ c: B& w$ l4 D4 zreturn head;}
! P3 {# P1 s- P z7 V联合就没讲,这里是因为课时的关系就没讲可惜啊!+ ~: ?1 w/ N1 S6 @, b
总之该课程讲到之处都是经典的值得在一次学习. |
|