
数据结构基础
文章平均质量分 71
俊雪恋
本科生在读,17年9月份去电子科大读研
展开
-
用数组模拟循环队列
我这里情况是这样的,队为空时:queue.front = queue.rear = 0;队满时:(PtrQ->rear+1)%MaxSize == PtrQ->front。很多人肯定会对mod有疑问,你就考虑当PtrQ->rear+1=MaxSize 的时候,如果不mod的话那么rear下一个位置就溢出了,也不会等于front了。原创 2017-03-29 11:12:20 · 723 阅读 · 0 评论 -
c语言实现二叉树先序,中序,后序(递归),层次遍历,求叶子节点个数及树的深度,下一篇写非递归的遍历
#include #include #define MAXSIZE 30typedef char ElemType;typedef struct TNode *BiTree;struct TNode { char data; BiTree lchild; BiTree rchild;};int IsEmpty_BiTree(BiTree *T) { if(*T原创 2017-04-04 14:50:28 · 14560 阅读 · 3 评论 -
c语言实现判断两颗树是否同构
在本题中认为如果两个树左右子树交换可以相同,也被认为是同构树。#include #define Tree int#define Null -1#define MAXSIZE 10struct Node{ char Element; Tree Left; Tree Right;}T1[MAXSIZE], T2[MAXSIZE];Tree BuildTree(str原创 2017-04-03 18:56:33 · 2995 阅读 · 5 评论 -
一元多项式加法
我们经常遇到两多项式相加的情况,在这里,我们就需要用程序来模拟实现把两个多项式相加到一起。首先,我们会有两个多项式,每个多项式是独立的一行,每个多项式由系数、幂数这样的多个整数对来表示。如多项式2x20- x17+ 5x9- 7x7+ 16x5+ 10x4 + 22x2- 15对应的表达式为:2 20 -1 17 5 9 - 7 7 16 5 10 4 22 2 -15 0。 默认把结原创 2017-04-02 17:30:03 · 971 阅读 · 0 评论 -
c语言实现数据结构中的链表源代码
#include #include typedef struct LNode *List;struct LNode { int data; List next;};struct LNode L;List InitList(List PtrL) { PtrL = (List) malloc(sizeof(L)); PtrL->next = NULL; return PtrL原创 2017-03-23 09:56:09 · 11154 阅读 · 1 评论 -
c语言实现链式队列
就是要注意下,有个结点是特殊的,那就是队列结点,一个是要指向链表的第一个结点,一个是要指向链表的第二个结点。元素类型是跟其他普通链表结点一样的。#include #include typedef struct Node *node;typedef struct QNode *Queue;struct Node{ int data; struct Node *next;};原创 2017-03-31 22:04:58 · 760 阅读 · 0 评论 -
c语言实现数据结构中顺序表的源代码
对于很多初学c语言的同学·,虽然都能理解数据结构中的思想,但是不一定能用c一行一行撸出一个完整的代码,我最近也正好在重新看数据结构,所以就把c语言实现数据结构源代码放出来帮助初学者。原创 2017-03-15 10:24:19 · 8790 阅读 · 2 评论 -
使用链表来模拟数据结构中的栈(链栈)
还是老问题想清楚栈顶是在链表头还是链表尾呢,当然链表头啊!#include #include typedef struct SNode *Stack;struct SNode{ int data; Stack next;};Stack CreateStack(){ Stack s; s = (Stack) malloc (sizeof(struct SNode)); s原创 2017-03-24 10:40:42 · 401 阅读 · 0 评论 -
用数组实现两个栈,要求最大地利用空间
对于这个问题要想清楚,两个栈的栈顶分别位于数组哪里,一个位于数组尾,一个位于数组末。#include #define N 10struct DStack{ int data[N]; int top1; int top2; };void Push(struct DStack *Ptrs, int x, int tag) { if(Ptrs->top2-Ptrs->top1原创 2017-03-23 21:59:24 · 464 阅读 · 0 评论 -
c语言实现归并排序
觉得归并排序没有什么好讲的,就是类似于合并两个有序的链表。#include void merge(int *a, int start, int mid, int end){ int n1 = mid - start + 1; int n2 = end - mid; int left[n1], right[n2]; int i, j, k; f原创 2017-03-28 10:28:17 · 509 阅读 · 0 评论 -
c语言实现数据结构中的栈(数组模拟)
c语言实现数据结构中的栈(数组模拟),这个是采用数组来模拟,下篇文章利用链表来模拟,也可以称为链栈吧!输出结果也可以验证栈是先进后出。#include #include #define N 10typedef struct SNode *Stack; struct SNode { int data[N]; int top;};Stack Init(Stack Ptrs) {原创 2017-03-23 11:05:19 · 795 阅读 · 0 评论 -
非递归算法实现树的先序遍历,中序遍历,后序遍历;也有树的层次遍历。
#include #include #define N 30typedef struct TNode *BiT;typedef struct SNode *Stack;struct SNode{ int top; BiT data[N];};struct TNode{ int data; BiT lchild, rchild;};void CreateStack原创 2017-04-08 15:05:23 · 813 阅读 · 0 评论 -
c语言实现快速排序
快速排序时间复杂度,最好:O(n*logn) 平均:O(n*logn) 最好:O(n^2)是不稳定排序算法。#include void quick_sort(int *a, int l, int h){ int i, j, x; i = l, j = h; while(i < j) { x = a[i]; while(i = x) j--; if(i <原创 2017-03-22 10:27:06 · 297 阅读 · 0 评论