数据结构
寰宇C++
这个作者很懒,什么都没留下…
展开
-
串的块链存储结构
#include <stdio.h>#include <stdlib.h>#include <string.h>#define linkNum 3 //全局设置链表中节点存储数据的个数typedef struct Link{ char a[linkNum]; //数据域可存放 linkNum 个数据 struct Link* next;//代表指针域,指向直接后继元素}link;//初始化链表,其中 head 为头指针,str 为存储的...原创 2021-02-18 14:20:19 · 510 阅读 · 2 评论 -
串的堆分配存储结构
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char *a1=NULL; char *a2=NULL; a1=(char*)malloc(10*sizeof(char)); strcpy(a1,"data.bian"); //将字符串"data.bian"复制给 a1 a2=(char*)malloc(10*sizeof(cha.原创 2021-02-18 13:30:26 · 290 阅读 · 0 评论 -
数据结构实践项目-------停车场管理系统
#include <stdio.h>#define MAX 3 //模拟停车场最多可停的车辆数,从0开始,可以停放4辆车//车的必要信息的结构体typedef struct{ int number; int arrive_time;}zanInode;//进入停车场的处理函数int push(zanInode* park,int* parktop,zanInode car){ //如果停车场已满,该车需进入便道等待(先返回 -1 ,在主程序中...原创 2021-02-08 17:33:06 · 549 阅读 · 0 评论 -
数据结构-------链式队列
#include <stdio.h>#include <stdlib.h>typedef struct QNode{ int data; struct QNode* next;}QNode;QNode* initQueue(){ QNode* queue=(QNode*)malloc(sizeof(QNode)); queue->next=NULL; return queue;}QNode* enQueue(Q...原创 2021-02-08 12:16:00 · 117 阅读 · 0 评论 -
数据结构------顺序队列《改进前》《改进后》
//改进前#include <stdio.h>//入队int enQueue(int *a,int rear,int data){ a[rear]=data; rear++; return rear;}void deQueue(int* a,int front,int rear){ //如果 front==rear,表示队列为空 while(front!=rear) { printf("出队元素:%...原创 2021-02-08 02:18:32 · 181 阅读 · 0 评论 -
数据结构实践项目--------进制转换器
#include <stdio.h>#include <string.h>#include <math.h>int top=-1; //top 变量时刻表示栈顶元素所在位置void push(char* a,char elem){ a[++top]=elem;}void pop(char* a){ if(top==-1) { return; } //输出时要按照正确的格式显示给用户 ...原创 2021-02-07 18:43:13 · 198 阅读 · 0 评论 -
数据结构-----链式栈
#include <stdio.h>#include <stdlib.h>typedef struct lineStack{ int data; struct lineStack* next;}lineStack;lineStack* push(lineStack* head,int a){ lineStack* line=(lineStack*)malloc(sizeof(lineStack)); line->data=a; ...原创 2021-02-07 15:44:36 · 131 阅读 · 1 评论 -
数据结构-------顺序栈
#include <stdio.h>//元素 elem 进栈int push(int* a,int top,int elem){ a[++top]=elem; return top;}//数据元素出栈int pop(int* a,int top){ if(top==-1) { printf("空栈"); return -1; } printf("弹栈元素:%d\n",a[top])...原创 2021-02-07 14:44:48 · 200 阅读 · 0 评论 -
数据结构---------《顺序存储结构模拟轮盘赌》《链式存储结构模拟轮盘赌》
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <iostream>using namespace std;typedef struct gambler{ int number;}gambler;int main(){ int n; int round=1; int location=1; int shootNum; ...原创 2021-02-06 22:47:17 · 266 阅读 · 0 评论 -
数据结构-----------双向循环链表
#include <stdio.h>#include <stdlib.h>typedef struct line{ struct line* prior; int data; struct line* next;}line;//创建双向循环链表line* initLine(line *head){ head=(line*)malloc(sizeof(line)); head->prior=NULL; head...原创 2021-02-06 20:53:34 · 144 阅读 · 0 评论 -
数据结构-----约瑟夫环(循环链表)
#include <iostream>#include <stdio.h>#include <stdlib.h>using namespace std;typedef struct node{ int number; struct node *next;}person;//创建约瑟夫环循环链表person* initLink(int n){ person * head=(person*)malloc(sizeof(perso...原创 2021-02-06 18:32:33 · 280 阅读 · 0 评论 -
数据结构--------双向链表
#include <stdio.h>#include <stdlib.h>//节点结构typedef struct line{ struct line *prior; int data; struct line *next;}line;//双链表的创建函数line* initLine(line *head){ //创建一个首元节点,链表的头指针为 head head=(line *)malloc(sizeof(line...原创 2021-02-05 12:14:25 · 158 阅读 · 0 评论 -
数据结构-----双链表的创建
#include <stdio.h>#include <stdlib.h>//节点结构typedef struct line{ struct line *prior; int data; struct line *next;}line;//双链表的创建函数line* initLine(line *head){ //创建一个首元节点,链表的头指针为 head head=(line *)malloc(sizeof(line...原创 2021-02-05 00:56:40 · 482 阅读 · 1 评论 -
数据结构-------静态链表的创建
#include <stdio.h>#define maxSize 6typedef struct{ int data; int cur;}component;//创建备用链表void reserveArr(component *array){ for(int i=0;i<maxSize;i++){ array[i].cur=i+1; array[i].data=-1; } array[m...原创 2021-02-04 15:52:55 · 312 阅读 · 0 评论 -
数据结构 -------单链表
//单链表的初始化#include <stdio.h>#include <stdlib.h>//链表中节点的结构typedef struct Link{ int elem; //数据域 struct Link *next; //指针域}link;//初始化链表的函数link *initLink(){ link *p=NULL; //创建头指针 link *temp=(link*)malloc(sizeof(link)).原创 2021-02-03 13:28:12 · 130 阅读 · 0 评论