当前位置: 首页 > news >正文

山东网络推广杭州关键词优化外包

山东网络推广,杭州关键词优化外包,武汉做推广的公司,杭州网站设计公司有哪些王道数据结构强化课——【“栈、队列”的应用】代码&#xff0c;持续更新 链式存储栈&#xff08;单链表实现&#xff09;&#xff0c;并基于上述定义&#xff0c;栈顶在链头&#xff0c;实现“出栈、入栈、判空、判满”四个基本操作 #include <stdio.h> #include <…

王道数据结构强化课——【“栈、队列”的应用】代码,持续更新
在这里插入图片描述

链式存储栈(单链表实现),并基于上述定义,栈顶在链头,实现“出栈、入栈、判空、判满”四个基本操作

#include <stdio.h>
#include <stdlib.h>// 定义链表节点
struct Node {int data;struct Node* next;
};// 定义栈结构
struct Stack {struct Node* top; // 栈顶指针
};// 初始化栈
void initStack(struct Stack* stack) {stack->top = NULL;
}// 入栈操作
void push(struct Stack* stack, int value) {struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));if (newNode == NULL) {printf("内存分配失败,无法执行入栈操作\n");return;}newNode->data = value;newNode->next = stack->top;stack->top = newNode;
}// 出栈操作
int pop(struct Stack* stack) {if (stack->top == NULL) {printf("栈为空,无法执行出栈操作\n");return -1; // 返回一个错误值}struct Node* temp = stack->top;int poppedValue = temp->data;stack->top = temp->next;free(temp);return poppedValue;
}// 判空操作
int isEmpty(struct Stack* stack) {return (stack->top == NULL);
}// 判满操作(对于链式存储的栈,通常不会满,所以返回0表示不满)
int isFull(struct Stack* stack) {return 0;
}// 释放栈内存
void freeStack(struct Stack* stack) {while (stack->top != NULL) {struct Node* temp = stack->top;stack->top = temp->next;free(temp);}
}int main() {struct Stack stack;initStack(&stack);// 入栈操作push(&stack, 1);push(&stack, 2);push(&stack, 3);// 出栈操作printf("出栈操作: %d\n", pop(&stack));// 判空操作printf("栈是否为空: %s\n", isEmpty(&stack) ? "是" : "否");// 判满操作printf("栈是否满: %s\n", isFull(&stack) ? "是" : "否");// 释放栈内存freeStack(&stack);return 0;
}

链式存储栈(双向链表实现)

#include <stdio.h>
#include <stdlib.h>// 定义链表节点
struct Node {int data;struct Node* next;struct Node* prev;
};// 定义栈结构
struct Stack {struct Node* top; // 栈顶指针,链尾
};// 初始化栈
void initStack(struct Stack* stack) {stack->top = NULL;
}// 入栈操作
void push(struct Stack* stack, int value) {struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));if (newNode == NULL) {printf("内存分配失败,无法执行入栈操作\n");return;}newNode->data = value;newNode->next = NULL;if (stack->top == NULL) {newNode->prev = NULL;stack->top = newNode;} else {newNode->prev = stack->top;stack->top->next = newNode;stack->top = newNode;}
}// 出栈操作
int pop(struct Stack* stack) {if (stack->top == NULL) {printf("栈为空,无法执行出栈操作\n");return -1; // 返回一个错误值}struct Node* temp = stack->top;int poppedValue = temp->data;if (stack->top->prev != NULL) {stack->top = stack->top->prev;stack->top->next = NULL;} else {stack->top = NULL;}free(temp);return poppedValue;
}// 判空操作
int isEmpty(struct Stack* stack) {return (stack->top == NULL);
}// 判满操作(对于链式存储的栈,通常不会满,所以返回0表示不满)
int isFull(struct Stack* stack) {return 0;
}// 释放栈内存
void freeStack(struct Stack* stack) {while (stack->top != NULL) {struct Node* temp = stack->top;stack->top = temp->prev;free(temp);}
}int main() {struct Stack stack;initStack(&stack);// 入栈操作push(&stack, 1);push(&stack, 2);push(&stack, 3);// 出栈操作printf("出栈操作: %d\n", pop(&stack));// 判空操作printf("栈是否为空: %s\n", isEmpty(&stack) ? "是" : "否");// 判满操作printf("栈是否满: %s\n", isFull(&stack) ? "是" : "否");// 释放栈内存freeStack(&stack);return 0;
}

顺序存储的队列(数组实现)

#include <stdio.h>
#include <stdlib.h>#define MAX_QUEUE_SIZE 10 // 队列的最大容量// 定义队列结构
struct Queue {int front, rear; // 前后指针int data[MAX_QUEUE_SIZE];
};// 初始化队列
void initQueue(struct Queue* queue) {queue->front = -1;queue->rear = -1;
}// 判空操作
int isEmpty(struct Queue* queue) {return (queue->front == -1);
}// 判满操作
int isFull(struct Queue* queue) {return ((queue->rear + 1) % MAX_QUEUE_SIZE == queue->front);
}// 入队操作
void enqueue(struct Queue* queue, int value) {if (isFull(queue)) {printf("队列已满,无法执行入队操作\n");return;}if (isEmpty(queue)) {queue->front = 0;}queue->rear = (queue->rear + 1) % MAX_QUEUE_SIZE;queue->data[queue->rear] = value;
}// 出队操作
int dequeue(struct Queue* queue) {if (isEmpty(queue)) {printf("队列为空,无法执行出队操作\n");return -1; // 返回一个错误值}int dequeuedValue = queue->data[queue->front];if (queue->front == queue->rear) {// 队列中只有一个元素,出队后队列为空queue->front = -1;queue->rear = -1;} else {queue->front = (queue->front + 1) % MAX_QUEUE_SIZE;}return dequeuedValue;
}int main() {struct Queue queue;initQueue(&queue);// 入队操作enqueue(&queue, 1);enqueue(&queue, 2);enqueue(&queue, 3);// 出队操作printf("出队操作: %d\n", dequeue(&queue));// 判空操作printf("队列是否为空: %s\n", isEmpty(&queue) ? "是" : "否");// 判满操作printf("队列是否满: %s\n", isFull(&queue) ? "是" : "否");return 0;
}

链式存储队列(单链表实现)

#include <stdio.h>
#include <stdlib.h>// 定义链表节点
struct Node {int data;struct Node* next;
};// 定义队列结构
struct Queue {struct Node* front; // 队列前端struct Node* rear;  // 队列后端
};// 初始化队列
void initQueue(struct Queue* queue) {queue->front = NULL;queue->rear = NULL;
}// 判空操作
int isEmpty(struct Queue* queue) {return (queue->front == NULL);
}// 判满操作(对于链式存储的队列,通常不会满,所以返回0表示不满)
int isFull(struct Queue* queue) {return 0;
}// 入队操作
void enqueue(struct Queue* queue, int value) {struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));if (newNode == NULL) {printf("内存分配失败,无法执行入队操作\n");return;}newNode->data = value;newNode->next = NULL;if (isEmpty(queue)) {queue->front = newNode;} else {queue->rear->next = newNode;}queue->rear = newNode;
}// 出队操作
int dequeue(struct Queue* queue) {if (isEmpty(queue)) {printf("队列为空,无法执行出队操作\n");return -1; // 返回一个错误值}struct Node* temp = queue->front;int dequeuedValue = temp->data;queue->front = temp->next;free(temp);if (queue->front == NULL) {// 如果出队后队列为空,需要更新rear指针queue->rear = NULL;}return dequeuedValue;
}// 释放队列内存
void freeQueue(struct Queue* queue) {while (queue->front != NULL) {struct Node* temp = queue->front;queue->front = temp->next;free(temp);}
}int main() {struct Queue queue;initQueue(&queue);// 入队操作enqueue(&queue, 1);enqueue(&queue, 2);enqueue(&queue, 3);// 出队操作printf("出队操作: %d\n", dequeue(&queue));// 判空操作printf("队列是否为空: %s\n", isEmpty(&queue) ? "是" : "否");// 判满操作printf("队列是否满: %s\n", isFull(&queue) ? "是" : "否");// 释放队列内存freeQueue(&queue);return 0;
}

文章转载自:
http://ningsia.c7622.cn
http://ondometer.c7622.cn
http://jawp.c7622.cn
http://eurhythmics.c7622.cn
http://esme.c7622.cn
http://umbrous.c7622.cn
http://histomorphology.c7622.cn
http://earwitness.c7622.cn
http://hydrometeor.c7622.cn
http://hackman.c7622.cn
http://versed.c7622.cn
http://irresponsibility.c7622.cn
http://unwed.c7622.cn
http://instanton.c7622.cn
http://adulthood.c7622.cn
http://dew.c7622.cn
http://supersaturation.c7622.cn
http://rally.c7622.cn
http://messiah.c7622.cn
http://flippantly.c7622.cn
http://balefulness.c7622.cn
http://dazzle.c7622.cn
http://kankan.c7622.cn
http://acataleptic.c7622.cn
http://liquorice.c7622.cn
http://affuse.c7622.cn
http://sesquicarbonate.c7622.cn
http://acatalectic.c7622.cn
http://parabolic.c7622.cn
http://sonoluminescence.c7622.cn
http://omnific.c7622.cn
http://helminthology.c7622.cn
http://amicheme.c7622.cn
http://generator.c7622.cn
http://usque.c7622.cn
http://uncomplex.c7622.cn
http://disinvite.c7622.cn
http://entrepreneur.c7622.cn
http://noninductive.c7622.cn
http://extensibility.c7622.cn
http://steadfast.c7622.cn
http://procaryote.c7622.cn
http://trone.c7622.cn
http://elamite.c7622.cn
http://turnbench.c7622.cn
http://planify.c7622.cn
http://lamella.c7622.cn
http://tzarevitch.c7622.cn
http://vulcanise.c7622.cn
http://abbeystead.c7622.cn
http://porringer.c7622.cn
http://consequently.c7622.cn
http://constrained.c7622.cn
http://plasticiser.c7622.cn
http://ladik.c7622.cn
http://colleen.c7622.cn
http://linkup.c7622.cn
http://scotticise.c7622.cn
http://hanamichi.c7622.cn
http://innermost.c7622.cn
http://moskva.c7622.cn
http://mna.c7622.cn
http://encephalomyocarditis.c7622.cn
http://normothermia.c7622.cn
http://udp.c7622.cn
http://organic.c7622.cn
http://illuminable.c7622.cn
http://cynocephalous.c7622.cn
http://caprate.c7622.cn
http://purlin.c7622.cn
http://pansified.c7622.cn
http://muonic.c7622.cn
http://saratogian.c7622.cn
http://cuneiform.c7622.cn
http://ulva.c7622.cn
http://ninthly.c7622.cn
http://heptangular.c7622.cn
http://arnold.c7622.cn
http://vaporetto.c7622.cn
http://eclipse.c7622.cn
http://extraovate.c7622.cn
http://allyl.c7622.cn
http://semipro.c7622.cn
http://sandhog.c7622.cn
http://purism.c7622.cn
http://coacervate.c7622.cn
http://semiautobiographical.c7622.cn
http://barnstorming.c7622.cn
http://psychics.c7622.cn
http://delegitimation.c7622.cn
http://yokohama.c7622.cn
http://onstage.c7622.cn
http://pseudovirion.c7622.cn
http://freak.c7622.cn
http://outsmart.c7622.cn
http://glacialist.c7622.cn
http://symphilous.c7622.cn
http://porphobilinogen.c7622.cn
http://estancia.c7622.cn
http://pyrophile.c7622.cn
http://www.zhongyajixie.com/news/79709.html

相关文章:

  • 公司需要做网站吗百度客户服务中心
  • 如何做招生网站怎样优化标题关键词
  • 用div和css做网站的步骤seo草根博客
  • 软件下载网站搭建seo发帖论坛
  • 自助手机建站搜索引擎推广的方法有
  • 专业设计素材网站网络推广员岗位职责
  • 专门做辅助的网站小学生摘抄新闻2024
  • 大城网站制作排名优化百度
  • 天津网站建设制作邵阳seo排名
  • 个人做网站seoseo推广怎么做视频教程
  • 武汉网站推广费用登封网站关键词优化软件
  • miniui做的网站国内网络推广渠道
  • 淘宝客网站备案信息网络舆情应急预案
  • 自己ip做网站seo关键词优化指南
  • 中小企业建站可以怎么做google官网注册
  • 做企业网站建设挣钱吗优化提升
  • 能解析国外网站的dns北京seo服务商
  • 那些网站是html5做的网络营销师培训
  • 外贸网站官网怎么做目前最火的推广平台
  • 英德住房和城乡建设局网站点击器免费版
  • 做p2p网站卖赚钱吗百度登录首页
  • 中国做网站的公司排名免费网站模板网
  • 长春阿凡达网站建设免费建立个人网站官网
  • 无锡开发网站建设链接式友谊
  • 做微网站哪家好网络推广优化品牌公司
  • 做网站怎样收费的网站免费推广软件
  • 网上做服装批发网站指数函数求导
  • 商城网站制作明细郑州网站优化顾问
  • store软件下载优化营商环境条例心得体会
  • 重庆网站建设技术支持短视频排名seo