数据结构与算法
immortalize
这个作者很懒,什么都没留下…
展开
-
顺序队列(可循坏利用的顺序循坏队列) ——以C语言为例
实现循环队列,避免假溢出等问题 //顺序队列 #include <stdio.h> #include <iostream> using namespace std; #define qElemType int #define QUEUE_INIT_SIZE 5 typedef struct sqQueue{ qElemType *elem;//队列首地址 int front;//队头下标 int rear;//队尾下标 }; //判空函数原创 2020-12-12 21:01:04 · 192 阅读 · 0 评论 -
链队列 ——以c语言为例
//链队列#include <stdio.h>#include <iostream>using namespace std;#define qElemType inttypedef struct qNode{ qElemType data; qNode *next;}*qPtr;typedef struct queue{ qPtr front; qPtr rear;}; //初始化队列;front,rear指针都指向头结点 void initQueue(q原创 2020-12-01 16:46:47 · 170 阅读 · 1 评论 -
汉诺塔问题 ——以c语言为例
#include <stdio.h>#include <iostream>using namespace std;//汉诺塔问题:利用递归的思想实现(分治法) void hannoi(int n,char A, char B ,char C){ if(1==n){ cout<<"Move" <<A<<"to"<<C<<endl; return ; } //1.算出n-1个盘子,将其从A移到B ha原创 2020-12-01 16:12:35 · 426 阅读 · 0 评论 -
链栈的应用 表达式运算
//链栈的应用 表达式运算#include <stdio.h>#include <iostream>using namespace std;#define sElemType inttypedef struct linkNode{sElemType data;//数据域 linkNode *next;//指针域}*linkStack;//判空函数(链栈为空返回1;不为空返回0)int isEmpty(linkStack top){return top==NUL原创 2020-12-01 15:49:45 · 237 阅读 · 0 评论 -
链栈的运用:行编辑程序问题 ——以c语言为例
行编辑程序问题:输入字符串,当遇到#字符时,自动撤回注销前一个字符,从而实现编辑字符串功能。#include <stdio.h>#include <stdio.h>#include <iostream>using namespace std;#define sElemType chartypedef struct linkNode{ sElemType data;//数据域 linkNode *next;//指针域 }*linkStack; //判原创 2020-11-17 15:28:25 · 304 阅读 · 0 评论 -
链栈的应用:括号匹配 ——以c语言为例
//链栈的应用:括号匹配 #include <stdio.h>#include <stdio.h>#include <iostream>using namespace std;#define sElemType inttypedef struct linkNode{ sElemType data;//数据域 linkNode *next;//指针域 }*linkStack; //判空函数(链栈为空返回1;不为空返回0) int isEmpty(l原创 2020-11-17 14:59:59 · 2714 阅读 · 2 评论 -
lintcode题目:尾部的零 ——以java语言为例
思路:阶乘中的每个数只有25的结合才可以组成尾部的零;而且很明显的知道阶乘中的数5的个数明显少于2的个数,所以可以由阶乘中5的倍数的个数从而决定尾部零的个数。在这里插入代码片public class Solution {/* @param n: An integer* @return: An integer, denote the number of trailing zeros in n!*/public long trailingZeros(long n) {// write your c原创 2020-09-12 15:48:25 · 111 阅读 · 0 评论 -
链栈的运用:进制转化 ——以c语言为例
#include <stdio.h>#include <iostream>using namespace std;#define sElemType inttypedef struct linkNode{ sElemType data;//数据域 linkNode *next;//指针域 }*linkStack; //判空函数(链栈为空返回1;不为空返回0) int isEmpty(linkStack top){ return top==NULL; }原创 2020-11-14 15:41:06 · 649 阅读 · 1 评论 -
链栈的功能实现(初始化,判空,压栈,弹栈,打印栈顶元素) ——以c语言为例
实现链栈功能算法时间复杂度:O(1);代码如下:#include <stdio.h>#include <iostream>using namespace std;#define sElemType inttypedef struct linkNode{ sElemType data;//数据域 linkNode *next;//指针域 }*linkStack; //判空函数(链栈为空返回1;不为空返回0) int isEmpty(linkStack top)原创 2020-11-14 15:12:35 · 566 阅读 · 0 评论 -
顺序栈的功能实现(初始化,判空,压栈,弹栈,打印栈顶元素,批量手动输入元素压栈弹栈) ——以c语言为例
顺序栈特点:FILO(先进后出)计算顺序栈的长度方法:length=s.top-s.base;时间复杂度:O(1)#include <stdio.h> #include <iostream> using namespace std; #define sElemType int //预定义类型 #define STACK_INIT_SIZE 10 //预定义初始容量 //定义顺序栈的结构体 typedef struct sqStack{ sEl原创 2020-11-03 19:16:44 · 544 阅读 · 0 评论 -
(详细注解+表达式完善版)单向链表的应用:一元多项式的表示与相加 ——以c语言为例
#include <stdio.h>#include <iostream>using namespace std; typedef struct node { double coef;// 多项式系数 int exp;// 多项式指数 node* next;//下一个结点的指针变量(指针域) }*poly;//初始化多项式 void initPoly(poly& p) { p = new node[1];//创建变量p存放第一个多项式 p-原创 2020-11-03 15:07:42 · 161 阅读 · 0 评论 -
单向链表的应用:一元多项式的表示与相加 ——以c语言为例
#include <stdio.h>#include <iostream>using namespace std;typedef struct node{ double coef;//多项式系数 int exp;//多项式指数 node *next;//指针域 }*poly;void initPoly(poly &p) { p=new node[1]; p->next=NULL; }void createPoly(poly &原创 2020-10-29 23:29:07 · 366 阅读 · 0 评论 -
(详细注释版)实现单链表的功能(创建,插入,查询,删除以及展示功能) ———以c语言为例
#include <stdio.h>#include <iostream>using namespace std;#define elemType int //创建单链表的结点结构 typedef struct node{ elemType data;//创建结点元素变量 node* next; //创建下一个结点指针变量 }*nodePtr;//将原来单链表的结点结构再定义为单链表的结点指针变量 //初始化单链表 void init原创 2020-10-19 17:07:58 · 483 阅读 · 0 评论 -
实现单链表的功能(创建,插入,查询,删除以及展示功能) ————以c语言为例
#include <stdio.h>#include <iostream>using namespace std;#define elemType int typedef struct node{ elemType data;//类型为int 如何预定义#define 为elemType,从而实现松耦合 node* next;}*nodePtr;void initLinkList(nodePtr &list){ nodePtr hea原创 2020-10-13 15:01:19 · 450 阅读 · 0 评论 -
顺序表的创建 详细说明版 ----以c语言为例
顺序表#include <stdio.h> #include <stdlib.h>//利用malloc函数 和 free函数#include <iostream>#define elemType int //预定义定义元素类型 int#define LIST_INIT_SIZE 10 // 预定义顺序表初始化容量using namespace std;//定义顺序表结构struct sqlist { ele...原创 2020-10-12 17:11:39 · 1083 阅读 · 0 评论 -
实现单链表的部分功能(创建,插入,查询以及展示功能) ————以c语言为例
#include <stdio.h>#include <iostream>using namespace std;typedef struct node{ int data;//类型为int 如何预定义#define 为elemType,从而实现松耦合 node* next;}*nodePtr;void initLinkList(nodePtr &list){ nodePtr head =new node[1]; //使指针变量(头原创 2020-09-29 17:44:03 · 178 阅读 · 0 评论 -
线性表的创建,实现插入,删除,查询和初始化创建功能 ——以c语言为例
#include <stdio.h>#include <stdlib.h>//morall free函数#include <iostream>#define elemType int#define LIST_INIT_SIZE 10using namespace std;struct sqlist { elemType* elem;//数组 int size= LIST_INIT_SIZE;//容量 int length;//长度}原创 2020-09-22 14:33:41 · 982 阅读 · 0 评论