数据结构
国服第l帅
仰之弥高,钻之弥坚
展开
-
判断一个单链表是否有环及环的链接点
给定一个单链表,只给出头指针h:1、如何判断是否存在环?2、如何知道环的长度?3、如何找出环的连接点在哪里?4、带环链表的长度是多少? 解法:1、对于问题1,使用追赶的方法,设定两个指针slow、fast,从头指针开始,每次分别前进1步、2步。如存在环,则两者相遇;如不存在环,fast遇到NULL退出。2、对于问题2,记录下问题1的碰转载 2016-06-27 11:44:02 · 227 阅读 · 0 评论 -
C语言栈的线性存储结构操作实现
/** 开发环境codeblock xxwu*/#include <stdio.h>#include <stdlib.h>#include <stdbool.h>#define STACK_INIT_SIZE 100#define STACK_INCREASEMENT 10typedef int ElemType;typed...原创 2018-09-06 18:13:45 · 392 阅读 · 0 评论 -
Codeblock写C语言代码报错 expected ';', ',' or ')' before '&' token
Codeblocks中写c语言代码,在编译时候报错:error: expected ':', ',', ';', '}' or '__attribute__' before '=' token错误原因:在C语言中是不存在引用,C语言中&表示的不是引用,仅仅是取地址符。因此,应该使用指针代替引用, 在主函数中传入地址。注意C语言中‘.’和‘->’的区别。报错代码如下...原创 2018-09-06 17:44:09 · 5867 阅读 · 1 评论 -
c语言归并两个有序链表
/**归并有序列表L1,L2到L3,使L3有序,从小到大xxwu*/#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef int ElemType;typedef struct LNode { ElemType data; struct LNode *...原创 2018-09-05 15:01:54 · 2679 阅读 · 0 评论 -
c语言实现双向链表
/**双链表操作开发环境codeblocks12.11xxwu*/#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef int ElemType;typedef struct DNode{ ElemType data; struct DNode ...原创 2018-09-05 13:42:13 · 4453 阅读 · 0 评论 -
c语言单链表操作实现
/**单链表操作开发环境codeblocks12.11xxwu*/#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef int ElemType;typedef struct LNode { ElemType data; struct LNode...原创 2018-09-05 13:39:57 · 323 阅读 · 0 评论 -
java实现图的深度优先搜索和广度优先搜索
java实现图的深度优先搜索和广度优先搜索原创 2016-06-18 12:51:57 · 2718 阅读 · 0 评论 -
二叉排序数的java实现
二叉排序树:所有左子树小于根节点值,所有右子树值大于根节点,采用中序遍历可以从小到大排序。本代码包含常用的插入和两种删除操作实现原创 2016-06-15 11:37:18 · 425 阅读 · 0 评论 -
判断二叉树左右对称
struct Node { Node *left; Node *right; Node() { left = right = NULL; }; }; bool Jud原创 2016-06-27 18:18:10 · 646 阅读 · 0 评论 -
C语言链表实现栈
/** 链表实现带头结点的栈,入栈用头插法 环境codeblocks*/#include <stdio.h>#include <stdlib.h>#include <stdbool.h>typedef int ElemType;typedef struct Node { ElemType data; struct...原创 2018-09-07 16:33:09 · 4173 阅读 · 1 评论