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

手工制作书签简单漂亮网络营销中的seo与sem

手工制作书签简单漂亮,网络营销中的seo与sem,哈尔滨市做网站公司,wordpress 图文混排Lei宝啊:个人主页(也许有你想看的) 愿所有美好不期而遇 前言 : 栈和队列的实现与链表的实现很相似,新瓶装旧酒,没什么新东西。 可以参考这篇文章: -------------------------无头单向不循环…

 Lei宝啊:个人主页(也许有你想看的)

愿所有美好不期而遇



前言 :

栈和队列的实现与链表的实现很相似,新瓶装旧酒,没什么新东西。

可以参考这篇文章:

-------------------------无头单向不循环链表和带头双向循环链表的创建---------------------------

 

逻辑图: 

 这里我们写顺序栈,不写链栈,因为栈数据的插入只能从栈顶入,栈顶出,这里链栈的优势就没有了,而大多数人所认为的另一个优势是顺序栈容易满?我们难道不能动态开一个,写一个checkcapacity吗,让他满了自动扩容,虽然有空间的损失,但这个并不是什么问题。再一个顺序栈的开辟与释放更为简单,直接释放掉动态开辟的数组空间就好。(当然,链栈也有其优势,但我更认可顺序栈)

头文件: 

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>typedef int DataType;
typedef struct Stack
{DataType* data;int top;int capacity;
}Stack;void Init(Stack *st);
void Push(Stack* st, DataType x);
void Pop(Stack* st);
DataType GetTop(Stack* st);
bool Empty(Stack* st);
void Destroy(Stack* st);
int Size(Stack* st);

Test文件(main):

#include "join_stack.h"void Test();int main()
{Test();return 0;
}void Test()
{Stack st;Init(&st);Push(&st, 1);Push(&st, 2);Push(&st, 3);Push(&st, 4);Push(&st, 5);Push(&st, 6);printf("size = %d\n", Size(&st));while (!Empty(&st)){printf("%d ", GetTop(&st));Pop(&st);}putchar('\n');Destroy(&st);
}

函数源文件:

#include "join_stack.h"void Init(Stack* st)
{assert(st);st->data = NULL;st->top = 0;st->capacity = 0;
}void Push(Stack* st, DataType x)
{assert(st);if (st->capacity == st->top){int newcapacity = (st->capacity == 0) ? 4 : st->capacity * 2;DataType* temp = (DataType*)realloc(st->data, sizeof(DataType) * newcapacity);if (temp == NULL){perror("realloc fail");exit(-1);}st->data = temp;st->capacity = newcapacity;}st->data[st->top++] = x;
}void Pop(Stack* st)
{assert(st);assert(st->top > 0);st->top--;
}DataType GetTop(Stack* st)
{assert(st);assert(st->top > 0);return st->data[st->top - 1];
}bool Empty(Stack* st)
{assert(st);return (st->top == 0);
}void Destroy(Stack* st)
{assert(st);free(st->data);st->data = NULL;st->top = st->capacity = 0;}int Size(Stack* st)
{assert(st);return st->top;
}


 

队列 

逻辑图:

队列我们就用链式结构,这和链表非常像,只是不能在中间插入,而且只能尾进头出。 

头文件:

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>typedef int DataType;
typedef struct Queue
{DataType data;struct Queue *next;
}Queue;typedef struct Q
{Queue* head;Queue* tail;int size;
}Q;void Init(Q *qq);
void Destroy(Q* qq);
void QueuePush(Q* qq, DataType x);
void QueuePop(Q* qq);
DataType GetQueueFrontNum(Q* qq);
DataType GetQueueBackNum(Q* qq);
bool Empty(Q* qq);
int Size(Q* qq);

 Test文件(main):

#define _CRT_SECURE_NO_WARNINGS 1
#include "newQueue.h"void Test();
int main()
{Test();return 0;
}void Test()
{Q qq;Init(&qq);QueuePush(&qq, 1);QueuePush(&qq, 2);QueuePush(&qq, 3);printf("%d ", GetQueueFrontNum(&qq));QueuePop(&qq);printf("%d \n", GetQueueFrontNum(&qq));QueuePush(&qq, 3);QueuePush(&qq, 4);QueuePush(&qq, 5);int head_num = GetQueueFrontNum(&qq);int tail_num = GetQueueBackNum(&qq);printf("%d %d\n", head_num, tail_num);printf("size = %d\n", Size(&qq));Destroy(&qq);
}

函数源文件:

#define _CRT_SECURE_NO_WARNINGS 1
#include "newQueue.h"void Init(Q* qq)
{assert(qq);qq->head = NULL;qq->tail = NULL;qq->size = 0;
}void QueuePush(Q* qq, DataType x)
{assert(qq);Queue* temp = (Queue*)malloc(sizeof(Queue));if (temp == NULL){perror("malloc fail");exit(-1);}temp->data = x;temp->next = NULL;if (qq->tail == NULL)qq->head = qq->tail = temp;else{qq->tail->next = temp;qq->tail = temp;}qq->size++;
}void QueuePop(Q* qq)
{assert(qq);assert(!Empty(qq));if (qq->head == qq->tail){free(qq->head);qq->head = qq->tail = NULL;}else{Queue* next = qq->head->next;free(qq->head);qq->head = next;}qq->size--;
}DataType GetQueueFrontNum(Q* qq)
{assert(qq);assert(!Empty(qq));return qq->head->data;
}DataType GetQueueBackNum(Q* qq)
{assert(qq);assert(!Empty(qq));return qq->tail->data;
}bool Empty(Q* qq)
{assert(qq);return qq->size == 0;
}void Destroy(Q* qq)
{assert(qq);free(qq->head);free(qq->tail);free(qq);
}int Size(Q* qq)
{assert(qq);return qq->size;
}

 

 

http://www.hkea.cn/news/34490/

相关文章:

  • 网络运营主要工作内容seo教程自学入门教材
  • 用其他商标在自己网站做宣传百度云网盘资源分享网站
  • 对商家而言网站建设的好处淘宝关键词查询工具哪个好
  • 做简单网站代码关键词推广价格
  • 做品牌折扣的网站百度推广的五大优势
  • 南宁比较有好的网站制作公司百度推广后台登录页面
  • 长沙企业网站排名优化windows优化大师和360哪个好
  • 珠海网站开发维护科技公司免费的网络推广渠道有哪些
  • wp建站系统微信营销管理软件
  • 本地打开WordPress慢百度seo优化分析
  • 适合友情链接的网站排名函数
  • 开发公司岗位设置广州seo招聘网
  • 国内web设计网站宣传推广
  • 深圳高端网站定制公司小时seo
  • wordpress主菜单下拉箭头怎么设置台州seo排名优化
  • 网站系统管理员模块关键词查找工具
  • 望江县建设局网站外贸seo推广招聘
  • 微信网站上传图片手机怎么制作网站
  • 简单做网站需要学什么搜索引擎有哪些网站
  • 网站备案信息加到哪里如何进行网站推广
  • 昭通网站制作aso优化技巧
  • 制作网站时怎样做滚动字幕新网站多久会被百度收录
  • 余姚物流做网站微信指数是搜索量吗
  • 怎样做网站轮播今日国内重大新闻事件
  • 想给大学做网站百度网盘搜索神器
  • jsp网站开发论文官方app下载安装
  • 关于机场建设的网站今日疫情最新情况
  • 网站域名注册服务商google浏览器官方
  • 通过网站开发工具怎么改自动跳网站百度指数有哪些功能
  • 可以发锚文本的网站百度搜索官方网站