随笔分类 -  数据结构

摘要:某城市有一个火车站,铁轨铺设如图所示,有n节车厢从A方向驶入车站,按进站顺序编号为1至n。你的任务是判断是否能让它们按照某种特定的顺序进入B方向的铁轨并驶出车站。为了重组车厢,你可以借助中转站C。这是一个可以停放任意多节车厢的车站,但由于末端封顶,驶入C的车厢必须按照相反的顺序驶出车站。例如:出站... 阅读全文
posted @ 2015-11-14 10:39 御心飞行 阅读(260) 评论(0) 推荐(0)
摘要:邻接矩阵: 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 typedef char VertexType[4]; 8 typedef int VRtype; 9 #define INF 1000... 阅读全文
posted @ 2015-09-15 17:40 御心飞行 阅读(141) 评论(0) 推荐(0)
摘要:小猴子下落时间限制:3000ms | 内存限制:65535KB难度:3描述有一颗二叉树,最大深度为D,且所有叶子的深度都相同。所有结点从左到右从上到下的编号为1,2,3,·····,2的D次方减1。在结点1处放一个小猴子,它会往下跑。每个内结点上都有一个开关,初始全部关闭,当每次有小猴子跑到一个开关... 阅读全文
posted @ 2015-09-05 12:21 御心飞行 阅读(334) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 typedef struct node{ 4 char data; 5 node *lchild,*rchild; 6 }binode,*bitree; 7 bitree createTree(bitree ... 阅读全文
posted @ 2015-09-04 22:25 御心飞行 阅读(223) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 typedef struct node 4 { 5 int value; 6 node *lchild,*rchild; 7 }*bitree,binode; 8 /*寻找要插入的双亲结点*/ 9 bool ... 阅读全文
posted @ 2015-09-04 20:29 御心飞行 阅读(153) 评论(0) 推荐(0)
摘要:二叉树先序递归遍历 1 int PreOrderTraverse(bitree T) 2 { 3 bitree p=T; 4 if(p) 5 { 6 coutdatalchild); 8 traverse(p->rchild); 9 }... 阅读全文
posted @ 2015-07-30 11:24 御心飞行 阅读(226) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 #define datatype char 5 typedef struct node 6 { 7 datatype data; 8 struct node *lchi... 阅读全文
posted @ 2015-07-30 10:43 御心飞行 阅读(759) 评论(0) 推荐(0)
摘要:元素的入栈出栈链栈: 1 #include 2 #include 3 using namespace std; 4 struct stack 5 { 6 char data; 7 stack *next; 8 }; 9 stack* initstack() ... 阅读全文
posted @ 2015-07-25 22:30 御心飞行 阅读(316) 评论(0) 推荐(0)
摘要:在一定大小的像素图像中,将同色区域的颜色值替换为其他颜色值,从而产生新的图像,输入数据,图像大小,指定的像素点坐标,要替换成的颜色。一开始出队操作写错了折腾半天,当队列中只有一个元素是出队后要将队首指针指向队尾指针。取定初始位置的坐标后,在此位置上下左右搜索,将满足要求的位置入队,然后经过此一层循环... 阅读全文
posted @ 2015-07-24 11:45 御心飞行 阅读(257) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 struct squeue 4 { 5 int data; 6 squeue *next; 7 }; 8 struct link 9 {10 squeue* front;11 squeue ... 阅读全文
posted @ 2015-07-23 16:44 御心飞行 阅读(157) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 using namespace std; 4 #define size 10 5 struct squeue 6 { 7 int queue[size]; 8 int front,rear; 9 };10 void initqu... 阅读全文
posted @ 2015-07-23 16:43 御心飞行 阅读(213) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 #define size 10 4 struct squeue 5 { 6 int queue[size]; 7 int front,rear; 8 int flag; 9 };10 void ini... 阅读全文
posted @ 2015-07-23 15:20 御心飞行 阅读(196) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 #define queuesize 20 4 struct squeue 5 { 6 int queue[queuesize]; 7 int front,rear; 8 }; 9 void initsqueu... 阅读全文
posted @ 2015-07-23 15:19 御心飞行 阅读(253) 评论(0) 推荐(0)
摘要:书上的例子 1 #include /*顺序栈*/ 2 using namespace std; 3 #define size 50 4 typedef struct node 5 { 6 int data[size][2]; /*每一层参数+当前返回值*... 阅读全文
posted @ 2015-07-22 20:54 御心飞行 阅读(152) 评论(0) 推荐(0)
摘要:利用链栈将中缀表达式转化为后缀表达式,然后利用顺序栈进行扫描计算,返回结果书上的代码 1 #include 2 #include 3 #include 4 #define size 50 5 using namespace std; 6 typedef struct node 7... 阅读全文
posted @ 2015-07-22 13:01 御心飞行 阅读(390) 评论(0) 推荐(0)
摘要:余数的序列正好与8进制数字序列相反,利用栈后进先出的特点,用栈来保存 1 #include //带头栈 2 #include 3 using namespace std; 4 typedef struct node 5 { 6 int data; 7 struct node *n... 阅读全文
posted @ 2015-07-21 18:26 御心飞行 阅读(291) 评论(0) 推荐(0)
摘要:链栈,写起来还是不熟 1 #include 2 #include 3 using namespace std; 4 typedef struct node 5 { 6 int data; 7 struct node* next; 8 }stacknode,*linkstack;... 阅读全文
posted @ 2015-07-21 17:33 御心飞行 阅读(199) 评论(0) 推荐(0)
摘要:书上的题目 链表元素排序,一开始准备交换节点,结果没搞好 1 #include 2 #include 3 using namespace std; 4 typedef struct node 5 { 6 int date; 7 struct node *next; 8 }*lin... 阅读全文
posted @ 2015-07-20 20:40 御心飞行 阅读(428) 评论(2) 推荐(0)
摘要:书上题目,取链表交集,放置于另一链表中,使用带头链表 1 #include 2 using namespace std; 3 typedef struct node 4 { 5 int date; 6 struct node *next; 7 }*linklist,listnod... 阅读全文
posted @ 2015-07-20 20:20 御心飞行 阅读(229) 评论(0) 推荐(0)
摘要:书上的题目,带头链表&不带头链表不带头链表为空时,判断:head==NULL;带头链表为空是,判断head->next=NULL;但对于链表的插入、删除会有不同,不带头链表对于头节点需要单独处理,而对于带头链表则不需要 1 #include 2 using namespace std; 3 typ... 阅读全文
posted @ 2015-07-20 19:47 御心飞行 阅读(619) 评论(0) 推荐(0)