线性结构
文章平均质量分 58
ccDLlyy
不忘初心,方得始终
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
单链表逆转
//链表逆转struct node{ int element; struct node* next;};struct node* revrese(struct node* oldhead){ struct node* newhead = NULL; struct node* temp; while(oldhead){ temp=ol原创 2016-09-11 10:24:22 · 399 阅读 · 0 评论 -
线性表的链式存储实现(无头结点)(陈越数据结构)
//线性表的链式存储实现(无头结点)#include struct node{ int element; struct node* next;};void Find2(struct node* head,int k){ struct node* p; p=head; int location=1; while(p&&location<k){原创 2016-09-21 19:20:50 · 1142 阅读 · 0 评论 -
中序表达式的直接计算
//假设各运算符和运算数之间均有空格//检验中缀表达式是否合法并计算结果//用两个栈,一个存运算数,一个存运算符#include #include #include #include #include char operators[100];//运算符double operand[100];//运算数int topr=-1;int topd=-1;int getresult原创 2016-10-13 17:25:26 · 1509 阅读 · 0 评论 -
队列的数组实现
法一:#include #include #define MAXSIZE 100//为了节省空间,采用循环数组,用到循环加1//非空时,front和rear指向端点元素//所以rear初始化为0,front为1//满的时候,一种情况是,front为1,rear为MAXSIZE-1,满足(queue->rear+2)%queue->capacity==queue->front//满原创 2016-10-13 19:04:56 · 564 阅读 · 0 评论 -
队列的链式实现
#include #include //写个带头结点的//front并不是指向第一个元素,因为头结点均为空头结点struct Lqueue{ int data; struct Lqueue* next;};struct queuerecord{ struct Lqueue* front; struct Lqueue* rear;};struct qu原创 2016-10-13 19:52:53 · 506 阅读 · 0 评论 -
栈的应用之平衡符号
//此代码只验证圆括号,方括号,大括号的平衡与否//做一个空栈//读入字符到文件末尾//如果一个字符是开放符号(即左括号),放入栈中//如果一个符号是封闭符号(即右括号)//一:如果此时栈空,报错//二:与栈头对比是否平衡,若对应,则平衡,并弹出栈头;若不对应,报错//在文件尾,若栈非空,报错#include #include char stack[100];//栈int t原创 2016-10-01 15:05:10 · 2176 阅读 · 0 评论 -
栈的应用之后缀表达式的计算(同时验证是否为合法的后缀表达式)
//假设运算数和运算符相互之间均有一个空格#include #include double stack[100];//建栈int top=-1;//栈头int isoperator(char data[]){ char temp=data[0]; if(strlen(data)==1&&(temp=='+'||temp=='-')||temp=='*'||temp=='原创 2016-10-01 16:49:11 · 2278 阅读 · 2 评论 -
栈的应用之中缀表达式转换为后缀表达式
//思路://1:当读到一个操作数,立即放到后缀表达式结果中。//2:当读到一个操作符,从存储运算符的栈中弹出元素到后缀表达式结果,直到出现级别更低的运算符为止,//最后再把此运算符推入栈,//但有一个例外,除非遇到),否者绝不会弹出(。//3:当读到一个(,压入栈中。//示例://中缀:a + b * c + ( d * e + f ) * g//后缀:a b c * + d e原创 2016-10-02 13:50:13 · 822 阅读 · 0 评论 -
队列的结构体封装实现(啊哈算法版,以解密QQ号为例)
#include #include struct queue{ int data[100]; int head; int tail;};int main(){ struct queue q; //队列初始化,head=tail=0 //tail总指向队列的下一个位置 q.head=0; q.tail=0; int n原创 2016-10-02 15:03:12 · 541 阅读 · 0 评论 -
栈和队列的实际应用:小猫钓鱼
#include #include #include struct queue{ int data[100]; int head; int tail;};struct stack{ int data[10]; int top;};int main(){ //两个队列用来存储小哈和小哼手中的牌 //栈用来存储桌面上的牌原创 2016-10-02 15:49:32 · 979 阅读 · 0 评论 -
单链表实现多项式相加
#include #include struct Node{ int coef;//系数 int expon;//指数 struct Node* next;};void DestroyPoly(struct Node* Poly)//释放实现多项式申请的空间{ struct Node* Temp; while(Poly!=NULL){原创 2016-10-27 22:16:16 · 2541 阅读 · 0 评论 -
找单链表中倒数第K个元素
//找单链表中倒数第K个元素,不保证存在,找不到,相关函数返回-1//思路://第一个游标在第一个元素处,另一个在第一个元素处开始右移,看看能不能使两个游标形成 最后一个与倒数第K个 的状态//若能,两个游标同时右移,直到右边游标到达末尾,这时第一个游标处就是所求元素处//若不能,返回-1#include #include #define k 4struct node{ i原创 2016-10-27 23:00:56 · 697 阅读 · 0 评论 -
线性表的链式存储实现(有头结点)
//线性表的链式存储实现(有头结点)#include struct node{ int element; struct node* next;};struct node* Insert(struct node* head,int i,int number){ int j=0; struct node* p; p=head; while(p原创 2016-09-21 19:37:12 · 777 阅读 · 0 评论 -
链表带不带头结点
链表如果带头结点,那么当插入.删除时,可无返回值;但如果没有头结点,必须返回头结点(防止删除和插入改变头结点)原创 2016-09-21 19:19:17 · 734 阅读 · 0 评论 -
线性表的顺序存储实现(陈越数据结构版)
//线性表的顺序存储实现(陈越数据结构版)#include #include #define MAXSIZE 100struct node{ int array[MAXSIZE]; int last;//最后一个元素的下标};struct node* Init(struct node * list){ list=(struct node*)malloc(siz原创 2016-09-21 17:48:31 · 641 阅读 · 0 评论 -
stack的单链表实现
栈有头节点,头节点后就是栈顶,即执行push操作时,插在头节点后;可以把弹出的元素放在另一个栈中;//栈的单链表实现#include struct node{ int element; struct node* next;} ;void Push(struct node* stack,int element)//栈头在stack后,即push在stack后{原创 2016-09-16 11:14:47 · 499 阅读 · 0 评论 -
stack的数组实现(结构体封装版)
//栈的数组实现(结构体封装版)//-->栈被定义为结构体指针,具体数组也被定义为指针,栈动态新建#define MAXSIZE 100struct node{ int capacity;//栈容量 int top;//栈顶 int* array;//数组存具体栈元素};void Push(struct node* stack,int element){原创 2016-09-16 11:48:20 · 1263 阅读 · 0 评论 -
线性表的链式实现(单链表)——有独立表头的实现
//定义结构体,以链表中元素为int为例struct node{ int data; struct node *next;};struct node* Insert(struct node*head,int element)//相同的,插到后面{ //findprevious and insert element after the position found;原创 2016-09-06 22:47:51 · 549 阅读 · 0 评论 -
线性表的链式实现(单链表)——无独立表头的实现
//非独立表头的,插入和删除操作均麻烦一些,考虑删掉的是不是表头,是不是插在表头前struct node{ int data; struct node* next;};struct node* Insert(struct node*head,int element){ struct node* p; p=(struct node*)malloc(sizeo原创 2016-09-07 23:33:17 · 504 阅读 · 0 评论 -
单链表——模拟链表
//模拟链表//利用两个数组,一个存数据,一个存“地址”//此处,right[t]存的为下标为t的元素的下一个元素的下标,最后一个下表的right[t]为0#define MAXN 5int main(){ int data[MAXN]; int right[MAXN];//right[0]相当于独立表头 memset(right,0,sizeof(right))原创 2016-09-08 14:09:13 · 488 阅读 · 0 评论 -
单链表--游标实现
对于一些语言,没有指针,所以用数组是实现链表的一种方式//链表的游标实现//array数组分两部分,一部分为链表部分,有一个独立头节点,下标为1//另一部分为freelist部分,也有独立的一个节点,下标为0,对于此部分,相当于一个栈//进行malloc操作时,从开头(下标0后)取空间//进行free操作时,被free的数放到开头(下标0后)#define MAXN 10str原创 2016-09-10 11:32:02 · 2075 阅读 · 0 评论 -
数据结构双语课->不带头节点的单链表实现
#include #include struct Node{ int data; struct Node* next;};struct Node* Init(){ return NULL;}struct Node* CreateNode(int data){ struct Node* tmp; tmp = (struct Node*)malloc原创 2016-10-09 17:08:23 · 649 阅读 · 0 评论 -
数据结构双语课->栈的链式实现
#include #include struct LStack{ int data; struct LStack* next;};struct LStack* createNode(int item){ struct LStack* tmp; tmp = (struct LStack*)malloc(sizeof(struct LStack)); i原创 2016-10-09 17:11:28 · 459 阅读 · 0 评论 -
数据结构资料中栈的两个应用
数据结构资料以中缀表达式转化为后缀表达式和后缀表达式的计算作为栈的应用讲解例题对于中缀表达式转化为后缀表达式:转换前后运算数的顺序是不变的,只是运算符的顺序改变,所以这时栈里要保存的是运算符而在后缀表达式的计算中,栈里要保存的是运算数原创 2016-10-09 18:07:46 · 792 阅读 · 0 评论 -
双链表
//双链表//head->a->b->c->NULL//head<-a<-b<-c#include struct node{ int element; struct node* previous; struct node* next;};struct node* FindPreofDelete(struct node* head,int element){原创 2016-09-11 09:16:02 · 533 阅读 · 0 评论 -
双向循环链表
//双向循环链表//有头节点#include #include struct node{ int element; struct node* next; struct node* previous;};void Insert(struct node* head,int number){ struct node* t; t=(struct nod原创 2016-09-21 11:58:14 · 431 阅读 · 0 评论 -
循环队列的几种形式
一:初始化head=0,tail=0,加入元素后,tail处无元素。满的时候(tial+1)%size==head,整个数组有一个位置没用到二:初始化head=0,tail=0,加入元素后,tail处有元素。满的时候(tail+1%size==head,整个数组有一个位置没用到三:初始化head=1,tail=0,加入元素后,tail处有元素。满的时候(tail+2)%size原创 2017-01-20 16:56:23 · 691 阅读 · 0 评论
分享