
数据结构
火箭丸子
艾比斯星球战神
展开
-
数据结构之数组实现栈结构
#include #include int *top(int *S)//返回栈顶位置 { return &S[0];}int Stack_Empty(int *S)//判断栈是否为空 { if(*top(S)==0)//栈顶=0,则栈为空 return 1; return 0;}int Stack_Full(int *S)//判断栈是原创 2011-11-30 10:51:03 · 917 阅读 · 0 评论 -
c++ 两个栈实现队列
#include #include #include /*两个栈实现队列*/using namespace std;templatestruct MyQueue{ void push(T &t) { s1.push(t); } T front() { if(s原创 2012-03-14 09:31:22 · 933 阅读 · 0 评论 -
数据结构--二叉树(链表)基本操作
#include "StdAfx.h" #include #include typedef struct tree{ int key; struct tree *left; struct tree *right; }*BiTree,Node; //循环创建二叉树 void CreateBiTree(Bi原创 2011-12-05 14:10:59 · 1021 阅读 · 0 评论 -
数据结构--非递归遍历二叉树(利用辅助栈)
#include "StdAfx.h" #include #include /*非递归方法前序遍历二叉树,利用辅助栈(指针数组实现)。由于对指针不是很熟悉,代码较为混乱,基本上实现遍历的功能。主要练习对结构体指针与链表的使用。*/ typedef struct tree{ int key; struct tree *left;原创 2011-12-06 14:27:57 · 1325 阅读 · 1 评论 -
数据结构--单链表实现队列1
#include #include /*单链表实现队列,目前的实现比较麻烦,额外使用了两个节点,但是尾节点基本没用,数据入队时间为O(n),出队为O(1),需要进一步修改,破坏了队列的常规判断空与满的方式*/ int length;//记录队列当前空余位置数 typedef struct node //队列节点 { int key; struct原创 2011-12-02 20:18:57 · 2579 阅读 · 0 评论 -
数据结构--单链表实现栈(头部插入数据的链表)
#include #include /*链表实现栈,只需要实现insert,delete方法*/int length;//栈的元素数量 typedef struct ss{//链表节点 int key; struct ss *next;}Node;void insert(Node *head,int num)//链表头部插入数据 { if(原创 2011-12-02 10:47:50 · 1557 阅读 · 0 评论 -
数据结构之双向链表,头部插入数据
#include #include /*双向链表,在表头插入数据*/typedef struct node{ int key; struct node *Next; struct node *Pre;}Node;void Insert(int num,Node *head)//插入新的节点 { Node *p = NULL; p = (Node *) malloc (s原创 2011-11-30 17:17:08 · 4363 阅读 · 1 评论 -
数据结构之简单链表(头部插入数据,查找,删除指定数据)
#include #include /*链表,在表头插入数据,使用了一个头结点head专门记录表头位置*/typedef struct node{ int key; struct node *Next;}Node;void Insert(int num,Node *head)//插入新的节点 { Node *p = NULL; p = (Node *) malloc (s原创 2011-11-30 16:31:47 · 2199 阅读 · 0 评论 -
数据结构之简单链表(尾部插入数据)
#include #include typedef struct node{ int key; struct node *Next;}Node;void Insert(int num,Node *head){ Node *L = NULL; Node *p = NULL; L = head; while (L->Next != NULL) { L = L->Nex原创 2011-11-30 15:59:16 · 10272 阅读 · 0 评论 -
数据结构之数组实现基础队列结构
#include #include int head;//保存队列头位置 ,始终指向最前面的元素 int tail;//保存队列尾位置,始终指向后一个位置 int Queue_Empty()//判断队列是否为空 { if(head==tail)//队头与队尾相等时,队列为空,删除元素时下溢 return 1; return 0;}int Queue_原创 2011-11-30 11:27:46 · 640 阅读 · 0 评论 -
二叉树的所有基本操作
#include #include #include #define STACK_INT_SIZE 100 //存储空间初始分配量#define STACKINCREMENT 10 //存储空间分配增量#define OK 1#define ERROR 0#define TRUE 1#define FALSE 0#define OVERFLOW -2原创 2012-04-16 21:00:08 · 1835 阅读 · 0 评论