
数据结构
文章平均质量分 60
lucky_mn
一入Java深似海。
展开
-
数据结构学习之栈和栈的操作源码
用一维数组模拟的顺序栈: #include "declear.h"#include "stdio.h"#define MAXSIZE 10typedef struct { SElemType data[MAXSIZE]; int top;}SqStack;Status InitStack(SqStack *S){ S->top = -1; return OK;}原创 2013-08-05 16:38:54 · 903 阅读 · 0 评论 -
char *和char[]的区别,困扰很长时间了,总结下
char c1[] = "hello";//char *c2 = "hello";//区别1:c1是一个局部数组,c2是一个全局数组。局部数组c1是局部变量,他对应的是内存中的栈;"hello"为字符串常量,放在只读的数据区域(区别普通的全局变量保存在静态数据区,静态数据区区域能改变变量值),所以c2指向全局区域内存。区别2:c1的值可以改变;*c1 = 'x';原创 2013-09-11 17:40:45 · 993 阅读 · 0 评论 -
如果函数的参数是一个指针,不要指望用该指针去申请动态内存。
/*栈类型*/typedef struct Node{ ElemType data; struct Node *next;}Node,*LinkStackPtr;typedef struct LinkStack{ LinkStackPtr top; int count;}LinkStack,*pLinkStack;/*初始化栈*//*对于空栈来说,栈表原定义的空栈是指头原创 2013-09-10 11:00:29 · 1270 阅读 · 0 评论 -
A+B for Input-Output Practice (I)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30061 Accepted Submission(s): 12935 Problem DescriptionYour task is to原创 2014-03-20 22:36:34 · 1190 阅读 · 0 评论 -
typedef 和 #define 修饰指针类型的区别
typedef 和 #define 二者修饰指针类型时,作用不同。 typedef int* pint; #define PINT int* const pint p; //p不可更改,p指向的内容可以更改,相当于int * const p; const PINT p; //p可以更改,p指向的内容不能更改,相当于 const int转载 2013-08-06 22:55:52 · 1188 阅读 · 0 评论 -
class类的sizeof计算
class no_virtual{public: void fun1() const{} int fun2() const { return a; }private: int a;}class one_virtual{public: virtual void fun1() const{} i原创 2013-09-17 16:57:10 · 1432 阅读 · 1 评论 -
几种交换两个数函数(swap函数)的写法和解析
#include using namespace std;/*值传递,局部变量a和b的值确实在调用swap0时变化了,当结束时,他们绳命周期结束*/void swap0(int a, int b){ int tem = a; a = b; b = a;}/*没有初始化指针就开始用,该函数是有问题的*/void swap1(int *a, int *b){ int *te原创 2013-08-20 17:06:13 · 6289 阅读 · 1 评论 -
《大话数据结构》读书笔记之冒泡排序和源码及优化算法源码
#include #define MAXSIZE 10typedef struct { int r[MAXSIZE + 1]; int length;}SqList;void InitSqList(SqList *L){ printf("please input the length of the sqlist:\n"); scanf("%d",&(L->length));原创 2013-08-16 11:03:36 · 1124 阅读 · 0 评论 -
《大话数据结构》读书笔记之二叉树的遍历源码,和习题
二叉树遍历:从根结点出发,按照某种次序依次访问二叉树的每个结点,使得每个结点被访问一次,且仅有一次。前序遍历:若二叉树为空,空操作返回;否则,先遍历根结点,再前序遍历左子树,再前序遍历右子树。(中左右)void PreTraversTree(PtrBiTree T){ if (T == NULL) { return; } printf("%d\n", T->data);原创 2013-08-08 17:12:52 · 1238 阅读 · 0 评论 -
《大话数据结构》读书笔记之快速排序源码及其优化
#include void Swap(int *a, int *b){ int tem = *a; *a = *b; *b = tem;}int Partition(int a[], int low, int high){ int pivotkey = a[low]; while (low < high) { while (low < high && a[high原创 2013-08-18 12:13:28 · 1447 阅读 · 0 评论 -
《大话数据结构》学习笔记之静态查找和源码
/*******************************查找基本概念:若关键字能够唯一的标识一个数据元素,则称该关键字为主关键字。能识别多个数据元素(或记录)的关键字,称之为次关键字。***********************************/int sequentialSerch(int *serchTable, int length, int key){ in原创 2013-08-14 15:35:52 · 988 阅读 · 0 评论 -
《大话数据结构》读书笔记之串和源码
#include #include #include #include #include "declear.h"#define MAXSIZE 40typedef char String[MAXSIZE + 1];/* 生成一个其值等于chars的串T */Status StrAssign(String T,char *chars){ unsigned int index原创 2013-08-07 22:11:59 · 1124 阅读 · 0 评论 -
《大话数据结构》读书笔记之链式队列和源码
/************************************链队列的主要知识点**************************************链队列其实是线性表的单链表,只不过只能尾进头出。队头指针front指向链表的头结点,队尾指针rear指向链表的终端结点。空队列是,队尾指针和队头指针都指向头结点。*****************************原创 2013-08-06 16:01:52 · 868 阅读 · 0 评论 -
《大话数据结构》学习笔记之顺序队列及其源码
/********************************知识点:************************************队列是只允许在一端(队头)进行插入操作,在另一端(队尾)进行删除操作的线性表(FIFO结构)循环队列:首尾相连的队列就是循环队列。循环队列满的条件:(rear + 1) % QueueSize = front (强调是循环队列,队列满时,原创 2013-08-06 12:18:30 · 1117 阅读 · 0 评论 -
斐波那契数列递归源码
#include/*/////////////////////////////////////功能:斐波那契数列日期:2013 8 6/////////////////////////////////////*/int fib(int i){ if (i < 2) { return i==0 ? 0:1; } return (fib(i-1) + fib(i-2));}原创 2013-08-06 09:45:05 · 1242 阅读 · 0 评论 -
用单循环链表实现约瑟夫问题。
约瑟夫问题是个有名的问题:N个人围成一圈,从第一个开始报数,第M个将被杀掉,最后剩下一个,其余人都将被杀掉。例如N=6,M=5,被杀掉的人的序号为5,4,6,2,3。最后剩下1号。#include #include #include "declear.h"typedef struct Node{ ElemType data; struct Node *next;}Node, *原创 2013-09-09 16:22:22 · 2003 阅读 · 0 评论