栈 链表 队列 堆的理解
文章平均质量分 58
qq_2773878606
学生
展开
-
队列和数组
#include #include #include #include #include#define N 10typedef struct Queue{ int nHead; int nTail; int nLen; int *pnArr;}Queue, *PQueue; //创建数组式队列,这里包含队列存储的个数,就是原创 2015-08-28 10:28:00 · 358 阅读 · 0 评论 -
两个栈来实现一个队列的C++代码
#include #include using namespace std;// 用两个stack实现一个queue, 以int类型为例吧class MyQueque{private: stack s1; // s1负责入队 stack s2; // s2负责出队 public: // 入队 void push(int x) { s1.push(x); }转载 2015-08-30 10:27:05 · 445 阅读 · 0 评论 -
二叉树的建立
#include#define N 7using namespace std;typedef struct node{ struct node* leftchild; struct node* rightchild; int data;}Node,*Bitree;//建立一个节点Node * creatnode(int i){ Node* p = new Node; p原创 2015-08-29 22:12:27 · 539 阅读 · 0 评论 -
链队列的建立、判空、入队、出队、求长、访头、清空和销毁
#includeusing namespace std;typedef struct node{ int data; struct node *next;}Node;//头指针和尾指针typedef struct{ Node *front; Node *rear;}Queue;void initQueue(Queue &Q){ Q.front = Q.rear转载 2015-08-29 21:50:18 · 887 阅读 · 0 评论 -
单链表反转
单链表的翻转是一道很基本的算法题。 方法1:将单链表储存为数组,然后按照数组的索引逆序进行反转。 方法2:使用三个指针遍历单链表,逐个链接点进行反转。 方法3:从第2个节点到第N个节点,依次逐节点插入到第1个节点(head节点)之后,最后将第一个节点挪到新表的表尾。 方法1的问题是浪费空间。方法2和方法3效率相转载 2015-08-30 10:22:58 · 438 阅读 · 0 评论 -
顺序栈
#include#include#include#include#define OK 1#define ERROR 0#define MAXSIZE 20using namespace std;typedef struct Stack{ int data[MAXSIZE]; int top;}sqstack;//建立一个栈首,int initial(sqstack *原创 2015-08-31 10:47:46 · 306 阅读 · 0 评论 -
顺序链表(数组形式)
#include#define MAX 20using namespace std;typedef struct node{ int data[MAX]; int length;}sqlist;void initial(sqlist* s){ s->length = 0;}bool listempty(sqlist* s){ if (s->length == 0)原创 2015-08-31 19:45:32 · 336 阅读 · 0 评论 -
顺序出栈操作
#include "stdio.h"#include "stdlib.h"#define OK 1#define ERROR 0/* 存储空间初始分配量 */#define MAXSIZE 20typedef int Status;/* SElemType类型根据实际情况而定,这里假设为int */typedef int SElemType;/* 顺序栈结构 */type原创 2015-08-31 10:47:04 · 411 阅读 · 0 评论 -
链式单链表
#include "stdio.h" #include "string.h"#include "ctype.h" #include "stdlib.h" #include "io.h" #include "math.h" #include "time.h"#define OK 1#define ERROR 0#define TRUE 1#define原创 2015-08-31 20:24:18 · 331 阅读 · 0 评论 -
从尾到头打印链表
从尾到头打印链表 题目:输入一个链表的头结点,从尾到头反过来打印出每个结点的值。链表结点定义如下:struct ListNode{ int m_nKey; ListNode *m_pNext;};解决这个问题肯定要遍历链表。遍历的顺序是从头到尾的顺序,可输出的顺序却是从尾到头。也就是说第一个遍历到的结点最后一个输出,而最后一个遍历到得结转载 2015-11-25 18:55:29 · 416 阅读 · 0 评论 -
链表反转的几种形式
// From curr reverse to end, return reversed linked list head.ListNode *unguarded_reverse(ListNode *prev, ListNode *curr, ListNode *end){ ListNode *next = NULL; while (curr != end)转载 2015-11-28 17:50:18 · 339 阅读 · 0 评论 -
二叉树(遍历、建立、深度)
1、二叉树的深度遍历 二叉树的遍历是指从根结点出发,按照某种次序依次访问二叉树的所有结点,使得每个结点被访问一次且仅被访问一次。 对于二叉树的深度遍历,有前序遍历二叉树、中序遍历二叉树、后序遍历二叉树三种形式,下面分别进行学习和介绍。1.1 二叉树的前序遍历 1)前序递归遍历 规则是若转载 2015-08-28 16:20:10 · 596 阅读 · 0 评论 -
双链表的建立、求长、定位、插入、删除、输出和释放
#includeusing namespace std;typedef struct node{ int data; struct node *next, *prior;}Node,*Dlist;//创建爽链表,循环的,呈现环状Dlist creatDlist(){ int num; Node *head, *p1, *p2; head = new Node; p1 =原创 2015-08-29 19:02:50 · 551 阅读 · 0 评论 -
单链表的建立,插入和释放
#includeusing namespace std;typedef struct node{ int data; struct node*next;}Node, *List; //相当于把strcut node另外命名为NOde和List* 指针类型List creatlist(){ Node* head, *p1, *p2;原创 2015-08-28 20:49:12 · 699 阅读 · 0 评论 -
单链表逆序
#includeusing namespace std;typedef struct node{ int data; struct node *next;}Node, *List;//建立带头结点的单链表List createList(){ Node *head, *p1, *p2; p1 = p2 = head = new Node;//头结点 int num;转载 2015-08-28 21:19:21 · 357 阅读 · 0 评论 -
栈和数组
#include #include #include #include #includetypedef struct Stack{ int nTop; int nLen; int *pnArr; //存储的是栈的值,nvalue}Stack, *PStack;原创 2015-08-28 08:57:30 · 445 阅读 · 0 评论 -
队列
为了操作上的方便,我们将队头指针指向链队列的头结点,而队尾指针指向终端结点。一个普通的链队列大概是下面这个样子:当队列为空时,front和rear都指向头结点。链队列的结构体定义与链栈一样,我们分两步定义链队列的结构体,首先是按链表来定义链队列的结点。/* QElemType类型根据实际情况而定,这里假设为int */t原创 2015-08-28 10:16:47 · 355 阅读 · 0 评论 -
单向链表循环
#include #include #include #include #includetypedef struct LoopLink{ int nValue; struct LoopLink *pNext;}LoopLink, *PLoopLink; //设置结点对象,包含两个成员,nvalue和指向下一个对象的原创 2015-08-28 09:25:33 · 314 阅读 · 0 评论 -
栈 链表综合使用
#include #include #include #include #includetypedef struct Stack{ int nValue; struct Stack *pNext; }Stack, *PStack; //链表的定义 ,属于一个对象,一个对象包含一个值,和原创 2015-08-28 08:59:10 · 338 阅读 · 0 评论 -
双向链表
由于通过地址能访问指定的内存存储单元,因此可以说,地址“指向”该内存存储单元(如同说,房间号“指向”某一房间一样)。故将地址形象化地称为“指针”,意思是通过它能找到以它为地址的内存单元。一个变量的地址称为该变量的“指针”。如果有一个变量专门用来存放另一个变量的地址(即指针),则它称为“指针变量”。在许多高级程序设计语言中有专门用来存放内存单元地址的变量类型,这就是指针类型。指针变量就是具有指针类型原创 2015-08-28 10:52:31 · 443 阅读 · 0 评论 -
函数调用和尾递归的一点认识
函数调用在大多数支持块结构的程序设计语言都支持函数或者子程序(函数和子程序的区别在于函数有返回值而子程序没有,在这里我们不区分这两个概念)。在进行函数调用和从函数返回时通常由一个被称为控制栈的运行时刻栈进行管理。每一个活跃的函数在控制栈中都会有一个相对应的活动记录,有时也称为栈帧。活动记录存储着函数调用时传递的参数信息和从函数返回时返回值与控制跳转的信息。 函数的活动记录需要包括下面的转载 2015-08-28 15:02:46 · 449 阅读 · 0 评论 -
图理解单链表的反转
如何把一个单链表进行反转?方法1:将单链表储存为数组,然后按照数组的索引逆序进行反转。方法2:使用三个指针遍历单链表,逐个链接点进行反转。方法3:从第2个节点到第N个节点,依次逐节点插入到第1个节点(head节点)之后,最后将第一个节点挪到新表的表尾。 方法1:浪费空间。 方法2:使用p和q连个指针配合工作,使得两个节点间的转载 2015-08-30 10:14:59 · 358 阅读 · 0 评论 -
链栈的建立、判空、入栈、出栈、求长、访顶、清空和销毁
#includeusing namespace std;typedef struct node{ int data; struct node*next;}Node, *stack;//初始化栈void initialsatck(stack &s){ s = new Node; s->next = NULL;}//判断栈是不是空的bool isempty(stack &原创 2015-08-29 21:44:44 · 4762 阅读 · 0 评论 -
单链表
#include#include#includeusing namespace std;typedef struct Node{ int data; struct Node* next;}Node;Node* creat(Node* head);void print(Node* head);Node* Delete(Node* head,int num);int main原创 2016-06-21 17:12:02 · 340 阅读 · 0 评论