2012年11月9日

数据结构:队列

摘要: 1#include<stdio.h>2#include<malloc.h>3typedefstructQueue4{5int*pBase;6intfront;7intrear;8}QUEUE;910voidinit(QUEUE*);11boolen_queue(QUEUE*,intval);12voidtraverse_queue(QUEUE*);13boolfull_queue(QUEUE*);14boolout_queue(QUEUE*,int*);15boolempty_queue(QUEUE*);161718intmain(void)19{20QUEUEQ;21 阅读全文

posted @ 2012-11-09 21:41 Your Song 阅读(137) 评论(0) 推荐(0) 编辑

2012年11月8日

数据结构:栈

摘要: 1#include<stdio.h>2#include<malloc.h>3#include<stdlib.h>45typedefstructNode6{7intdata;8structNode*pNext;9}NODE,*PNODE;10typedefstructStack11{12PNODEpTop;13PNODEpBottom;14}STACK,*PSTACK;1516voidinit(PSTACKpS);17voidpush(PSTACK,int);18voidtraverse(PSTACK);19boolpop(PSTACK,int*);20boo 阅读全文

posted @ 2012-11-08 18:27 Your Song 阅读(166) 评论(0) 推荐(0) 编辑

2012年11月7日

数据结构:链表插入和删除算法的演示

摘要: 1#include<stdio.h>2#include<malloc.h>3#include<stdlib.h>45typedefstructNode//要理解typedef的用法6{7intdata;8structNode*pNext;9}NODE,*PNODE;10PNODEcreat(void);11voidtraverse(PNODEpHead);//注意函数的返回值类型12boolempty(PNODEpHead);13intlength(PNODE);14boolinsert(PNODE,int,int);15booldelet(PNODE,in 阅读全文

posted @ 2012-11-07 19:54 Your Song 阅读(1255) 评论(0) 推荐(0) 编辑

2012年11月6日

数据结构:连续存储数组的算法

摘要: 1#include<stdio.h>2#include<malloc.h>3#include<stdlib.h>45structpArr6{78int*pBase;9intlen;10intcnt;11};12voidinit(structpArr*arr,intlength);13voidshow(structpArr*arr);14boolis_empty(structpArr*arr);15boolis_full(structpArr*arr);16boolappend(structpArr*arr,intval);17boolinsert(struc 阅读全文

posted @ 2012-11-06 08:14 Your Song 阅读(269) 评论(0) 推荐(0) 编辑

2012年11月4日

数据结构预热:跨函数使用内存

摘要: 1#include<stdio.h>2#include<malloc.h>34structStudent5{6intsid;7intage;8};9structStudent*creat(void);10voidshow(structStudent*);11intmain(void)12{13structStudent*ps;14ps=creat();15show(ps);16return0;17}18structStudent*creat(void)19{20structStudent*pst=(structStudent*)malloc(sizeof(structS 阅读全文

posted @ 2012-11-04 20:52 Your Song 阅读(158) 评论(0) 推荐(0) 编辑

数据结构预热:malloc动态分配内存

摘要: 1#include<stdio.h>2#include<malloc.h>34intmain(void)5{6intlen;7printf("输入数组的长度:len=");8scanf("%d",&len);9int*pArr=(int*)malloc(sizeof(int)*len);10for(inti=0;i<len;i++)11scanf("%d",pArr+i);//也可以写成&pArr[i];12for(i=0;i<len;i++)13printf("%d\n& 阅读全文

posted @ 2012-11-04 20:11 Your Song 阅读(443) 评论(0) 推荐(0) 编辑

数据结构,指针预热

摘要: 1#include<stdio.h>2voidf(int*p,intlen)3{4p[3]=10;//相当于*(P+3)5inti;6for(i=0;i<len;i++)7{8printf("%d\n",*(p+i));9}10}11intmain()12{13inta[]={1,2,3,4,5};14f(a,5);15printf("a[3]=%d\n",a[3]);1617return0;18} 阅读全文

posted @ 2012-11-04 11:01 Your Song 阅读(113) 评论(0) 推荐(0) 编辑

2012年9月6日

枚举

摘要: 1//枚举就是把一个事物所有的取值给一一列举出来2#include<stdio.h>3//只定义了一个数据类型,并没有定义变量,该数据类型的名字是enumWeekDay4enumWeekDay5{6Monday,TuseDay,WednesDay,ThusDay,FriDay,SaturDay,SunDay7};89voidf(enumWeekDayi)10{11switch(i)12{13case0:14printf("周一\n");15break;16case1:17printf("周二\n");18break;19case2:20pri 阅读全文

posted @ 2012-09-06 16:52 Your Song 阅读(132) 评论(0) 推荐(0) 编辑

动态构造存放学生信息的结构体数组,按分数排序输出

摘要: 1/*2动态构造存放学生信息的结构体数组,按分数排序输出3*/4#include<stdio.h>5#include<malloc.h>67structStudent8{9intage;10floatscore;11charname[100];1213};1415intmain(void)16{17inti,j;18intlen;19structStudent*pArr;20structStudentt;//临时变量要定义成structStudentt2122printf("请输入学生的个数:\n");23printf("len=" 阅读全文

posted @ 2012-09-06 14:21 Your Song 阅读(2306) 评论(0) 推荐(0) 编辑

冒泡排序

摘要: /*冒泡排序*/# include <stdio.h>void sort(int * pArr, int len){ int i, j, t; for(i=0; i<len-1; i++) { for(j=0; j<len-1-i; j++) //要弄懂流程,用一个例子来理解。 { if(pArr[j] > pArr[j+1]) { t = pArr[j]; pArr[j] = pArr[j+1]; pArr[j+1]=t; } } } }int main(void){ int a[6] = {10, 2, -4 , 11, 12, 0}; int... 阅读全文

posted @ 2012-09-06 13:39 Your Song 阅读(139) 评论(0) 推荐(0) 编辑

导航