|
|

楼主 |
发表于 2005-3-31 02:09:19
|
显示全部楼层
前几天看完啦折大的c因为忙于看数据结构就忘啦点评完.下面接着点评! h$ _* R* \$ v5 K8 V- }
对于指针课程分的很详细讲有下面的例子是指针数组
& U$ i U8 u3 c1 e#include<stdio.h>* S8 `3 ~7 e2 x$ N4 B4 @& K
void main()* j: S& r+ C0 m" T+ f
{5 p2 i% S( b2 l' ?$ ]! P
char *name[4]={"wang","li","zhao",jin"};
6 m" o1 k7 k8 d5 Achar **pp;- P: P9 I5 R' F: W0 i# y( q
for(pp=name;pp<name+4;pp++)2 v8 ]. S1 B* ~- c
printf("%c",**pp+1);5 Q0 ~ m# j9 u5 d- |" j
}
, _$ a* c9 C7 P) _/ I3 d但我唯一觉得不足的是数组指针的例子太少可能和课时太少有关吧!对于链表我认为是讲的最好的部分在该课程中从算法到流程及最后的程序书写下面给出链表的一个例子:
* ~0 h7 l X& X# t6 L$ L#include "stdio.h"" K- D7 w+ c2 U" V! ]3 j% g; |
struct student{
" d5 _7 I' U- u9 Bint num;3 M. f6 ^$ G, [& W+ q: b7 Z* `9 k3 h
float score;' X) s" F* T: q4 d/ Q
struct student *next;
, [! @4 P Z& j' B4 a};! v/ M% \$ A, E" }
struct student *creat();
0 |' P% q; t! Z+ Y, U Kmain()
) R8 W/ D/ _8 x6 j" Q4 D2 y/ w{1 i" L! b: R7 a0 @; H+ G( E H
struct student *head;
9 {& N' e; [, J+ T; E% Lhead=creat();: p/ o1 {4 Y! u$ s7 Z
}
( ]% I& T: ~6 hstruct student *creat()
' c; b- ?8 z9 Q& z# e* R3 ^{struct student *head,*tail,*p;float score;+ X2 D4 f: ~7 S+ b
int num,size=sizeof(struct student);
: f x- O1 e5 a: r- S" v8 s( p. Yhead=tail=NULL;
# G4 D5 t$ h! M4 F9 cscanf(%d%f",&num,&score);
# g1 _+ j7 N7 A+ \1 ewhile(num){
: a5 D3 w4 m @p=(stuct student *)malloc(size);
- F! D) @5 _5 {p->num=num;p->score=score;
' s1 ~$ `8 C& l( C0 vp->next=NULL;6 ~$ q/ p* E/ ~
if(head==NULL)head=p;
; W9 R- ~4 X) r; Oelse tail->next=p;, G" l0 g5 C6 }( A
tail=p;2 U! F0 ]$ o1 L. \ ?% i( k
scanf("%d%f",&num,&score);0 S3 L! @1 ?& E5 Z4 ^. u
}% e5 O5 _$ k5 I; r3 P" f
return head;}
# V c- s% H5 M) E c联合就没讲,这里是因为课时的关系就没讲可惜啊!
* b" E- ^( M/ C7 I- V总之该课程讲到之处都是经典的值得在一次学习. |
|