#ifndef  __MY_SEQLIST_H__
#define __MY_SEQLIST_H__ typedef void SeqList;
typedef void SeqListNode; //链表 创建
SeqList* SeqList_Create(int capacity); //链表 销毁
void SeqList_Destroy(SeqList* list); ////链表 清空
void SeqList_Clear(SeqList* list); //链表 长度
int SeqList_Length(SeqList* list); //链表 容量
int SeqList_Capacity(SeqList* list); //链表 在某一个位置 插入元素
int SeqList_Insert(SeqList* list, SeqListNode* node, int pos); //获取某一个位置的链表结点
SeqListNode* SeqList_Get(SeqList* list, int pos); //删除某一个位置的结点
SeqListNode* SeqList_Delete(SeqList* list, int pos); #endif //__MY_SEQLIST_H__ #ifndef _MY_SEQQUEUE_H_
#define _MY_SEQQUEUE_H_ typedef void SeqQueue; //创建队列
SeqQueue* SeqQueue_Create(int capacity); //销毁 队列
void SeqQueue_Destroy(SeqQueue* queue); //清空 队列
void SeqQueue_Clear(SeqQueue* queue); //向队列中添加 元素
int SeqQueue_Append(SeqQueue* queue, void* item); //从 队列 中 提取 元素
void* SeqQueue_Retrieve(SeqQueue* queue); //求 队列 队头元素
void* SeqQueue_Header(SeqQueue* queue); //队列 长度
int SeqQueue_Length(SeqQueue* queue); //队列容量
int SeqQueue_Capacity(SeqQueue* queue); #endif //_MY_SEQQUEUE_H_
#define  _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "seqlist.h" //用数组来模拟线性表
typedef struct _tag_SeqList
{
int capacity;
int length;
//int *node[100];
int **node; //int node[capacity] //
//int *node[capacity]; //int *node; // int node[i]===> *(node+i)
}TSeqList; //链表 创建
SeqList* SeqList_Create(int capacity) //O(1)
{
int ret;
TSeqList *tmp = NULL;
tmp = (TSeqList *)malloc(sizeof(TSeqList));
if (tmp == NULL)
{
ret =;
printf("func SeqList_Create() err :%d \n", ret);
return NULL;
}
memset(tmp, , sizeof(TSeqList));
tmp->capacity = capacity;
tmp->length = ;
tmp->node = (int **)malloc(sizeof(void *) * capacity);
if (tmp->node == NULL)
{
ret = ;
printf("func SeqList_Create() malloc err :%d \n", ret);
return NULL;
}
memset(tmp->node, , sizeof(void *) * capacity); return tmp;
} //链表 创建
int SeqList_Create2(int capacity, SeqList**handle)
{
int ret = ;
TSeqList *tmp = NULL;
tmp = (TSeqList *)malloc(sizeof(TSeqList));
if (tmp == NULL)
{
ret =;
printf("func SeqList_Create2() err :%d \n", ret);
return ret;
}
memset(tmp, , sizeof(TSeqList));
tmp->capacity = capacity;
tmp->length = ;
tmp->node = (int **)malloc(sizeof(void *) * capacity);
if (tmp->node == NULL)
{
ret = ;
printf("func SeqList_Create2() malloc err :%d \n", ret);
return ret;
} *handle = tmp;
return ret;
} //链表 销毁
void SeqList_Destroy(SeqList* list) //O(1)
{
TSeqList *tmp = NULL;
if (list == NULL)
{
return ;
} tmp = (TSeqList *)list; if (tmp->node != NULL)
{
free(tmp->node);
}
free(tmp);
return ;
} ////链表 清空
void SeqList_Clear(SeqList* list) //O(1)
{
TSeqList *tmp = NULL;
if (list == NULL)
{
return ;
} tmp = (TSeqList *)list;
tmp->length = ;
memset(tmp->node, , (tmp->capacity * sizeof(void *)) ); return ;
} //链表 长度
int SeqList_Length(SeqList* list) //O(1)
{
TSeqList *tmp = NULL;
if (list == NULL)
{
return -;
}
tmp = (TSeqList *)list; return tmp->length;
} //链表 容量
int SeqList_Capacity(SeqList* list) //O(1)
{
TSeqList *tmp = NULL;
if (list == NULL)
{
return -;
}
tmp = (TSeqList *)list;
return tmp->capacity;
} //链表 在某一个位置 插入元素
int SeqList_Insert(SeqList* list, SeqListNode* node, int pos) //O(n)
{
TSeqList *tList = NULL;
int i = ;
if (list == NULL || node==NULL)
{
return -;
}
tList = (TSeqList *)list;
//如果满了
if (tList->length >= tList->capacity)
{
return -;
} //pos位置的容错处理
if (pos > tList->length )
{
pos = tList->length;
} for (i=tList->length; i>pos; i--) //n
{
tList->node[i] = tList->node[i-];
} tList->node[i] = (int* )node; //ok
tList->length ++; return ;
} //获取某一个位置的链表结点
SeqListNode* SeqList_Get(SeqList* list, int pos) //O(1)
{
TSeqList *tList = NULL;
SeqListNode *tmp = NULL; tList = (TSeqList *)list; if (list == NULL || pos< || pos >=tList->length )
{
return NULL;
}
tmp = tList->node[pos]; return tmp;
} //删除某一个位置的结点
SeqListNode* SeqList_Delete(SeqList* list, int pos) ////O(n)
{
int i = ;
TSeqList *tList = NULL;
SeqListNode *tmp = NULL; tList = (TSeqList *)list;
if (list == NULL || pos < || pos >= tList->length)
{
return NULL;
}
tmp = tList->node[pos]; // pos = 3
for (i=pos+; i<tList->length; i++)
{
tList->node[i-] = tList->node[i]; }
tList->length --;
return tmp;
} #define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <string.h>
#include <stdio.h> #include "seqqueue.h"
#include "seqlist.h" //创建一个队列 相当于 创建一个顺序表
SeqQueue* SeqQueue_Create(int capacity)
{
return SeqList_Create(capacity);
} //销毁 队列 相当于 销毁 一个 顺序表
void SeqQueue_Destroy(SeqQueue* queue)
{
SeqList_Destroy(queue);
} //清空 队列 相当于 清空 一个 顺序表
void SeqQueue_Clear(SeqQueue* queue)
{
SeqList_Clear(queue);
} //向队列尾部添加一个元素 相当于 向线性表的尾部添加元素
int SeqQueue_Append(SeqQueue* queue, void* item)
{
return SeqList_Insert(queue, item, SeqList_Length(queue));
} //提取队头元素 相当于 删除链表0号位置元素
void* SeqQueue_Retrieve(SeqQueue* queue)
{
return SeqList_Delete(queue, ) ;
} //获取队头元素 相当于 获取 链表0号位置元素
void* SeqQueue_Header(SeqQueue* queue)
{
return SeqList_Get(queue, );
} int SeqQueue_Length(SeqQueue* queue)
{
return SeqList_Length(queue);
} int SeqQueue_Capacity(SeqQueue* queue)
{
return SeqList_Capacity(queue);
}
#define  _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "seqqueue.h" void main()
{
int i = , a[]; SeqQueue *queue = NULL; for (i=; i<; i++)
{
a[i] = i + ;
} queue = SeqQueue_Create(); //向队列的尾部 添加元素
for (i=; i<; i++)
{
SeqQueue_Append(queue, a + i);
} //获取队列的属性
printf("capacity:%d \n", SeqQueue_Capacity(queue));
printf("length:%d \n", SeqQueue_Length(queue));
printf("队头: %d \n", *( (int *)SeqQueue_Header(queue) )); //销毁 队列 while (SeqQueue_Length(queue) > )
{
int tmp;
tmp = *( (int *)SeqQueue_Retrieve(queue) );
printf("%d ", tmp);
}
SeqQueue_Destroy(queue); printf("hello...\n");
system("pause");
return ;
}

C 队列顺序存储的更多相关文章

  1. [置顶] ※数据结构※→☆线性表结构(queue)☆============队列 顺序存储结构(queue sequence)(八)

    队列是一种特殊的线性表,特殊之处在于它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作,和栈一样,队列是一种操作受限制的线性表.进行插入操作的端称为队尾,进行删除操作的 ...

  2. [置顶] ※数据结构※→☆线性表结构(queue)☆============循环队列 顺序存储结构(queue circular sequence)(十)

    循环队列 为充分利用向量空间,克服"假溢出"现象的方法是:将向量空间想象为一个首尾相接的圆环,并称这种向量为循环向量.存储在其中的队列称为循环队列(Circular Queue). ...

  3. 队列顺序存储 - 设计与实现 - API函数

    队列是一种特殊的线性表 队列仅在线性表的两端进行操作 队头(Front):取出数据元素的一端 队尾(Rear):插入数据元素的一端 队列不允许在中间部位进行操作! queue常用操作 销毁队列 清空队 ...

  4. 基于python实现顺序存储的队列代码

    """ 队列-顺序存储 seqqueue.py 代码实现 """ # 自定义异常类 class QueueError(Exception): ...

  5. (转)java redis使用之利用jedis实现redis消息队列

    应用场景 最近在公司做项目,需要对聊天内容进行存储,考虑到数据库查询的IO连接数高.连接频繁的因素,决定利用缓存做. 从网上了解到redis可以对所有的内容进行二进制的存储,而java是可以对所有对象 ...

  6. 队列链式存储 - 设计与实现 - API函数

    队列相关基础内容参我的博文:队列顺序存储 - 设计与实现 - API函数 队列也是一种特殊的线性表:可以用线性表链式存储来模拟队列的链式存储. 主要代码: // linkqueue.h // 队列链式 ...

  7. 预热一下吧《实现Redis消息队列》

    应用场景 为什么要用redis?二进制存储.java序列化传输.IO连接数高.连接频繁 一.序列化 这里编写了一个java序列化的工具,主要是将对象转化为byte数组,和根据byte数组反序列化成ja ...

  8. Java利用Redis实现消息队列

    应用场景 为什么要用redis?二进制存储.java序列化传输.IO连接数高.连接频繁 一.序列化 这里编写了一个java序列化的工具,主要是将对象转化为byte数组,和根据byte数组反序列化成ja ...

  9. [PHP] 2018年终总结

    去掉敏感信息后的不完整版 ==========================================================================2018年12月29日 记 ...

随机推荐

  1. 在Linux上运行C#

    众所周知,C#是Microsoft推出的.NET语言,只能在.NET平台上运行,例如Win 9x.ME.NT.2000.XP和Win CE之类的操作系统.但是,现在却有了一个叫做Mono的项目,它的目 ...

  2. 「拒絕存取路徑 'C:\Users\xxx\AppData\Local\Temp\Temporary ASP.NET Files\apname\3a1b3704\f7fc6d0c\App_Code.l8ieogii.0.cs」的錯誤!

    修改web.config中的system.web->compilation tag中,多加入tempDirectory="可存取的目錄"   <system.web&g ...

  3. android studio 安装总结

    Android Studio 的安装和配置篇(Windows篇<转> http://www.jianshu.com/p/fc03942548cc# 中间gradle下载比较慢:解决方法 需 ...

  4. CI的知识点

    1. 超级对象中$this->uri 获取pathinfo中的值,$this->uri->segment(n)中的n表示第几个参数 如:/welcome/index/1  使用$th ...

  5. Android中Bitmap和Drawable,等相关内容

    一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...

  6. Poj 1163 The Triangle 之解题报告

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 42232   Accepted: 25527 Description 7 3 ...

  7. 【HTML】Advanced7:HTML5 Forms Pt. 2: Attributes and Data Lists

    1.<label for"" ></label> <input type="email" placeholder=" & ...

  8. 推荐vpn的文章

    http://wsgzao.github.io/post/fq/ 免费方案 各个平台的解决方案都不唯一,请认真阅读原文中的说明部分 百度浏览器 你这么大摇大摆提供FQ插件,真不用担心360菊(jǔ)爆 ...

  9. Delphi监视进程并结束进程

    监视进程并结束进程在很多地方都用到这里借前人的经验写了个小例子: 以QQ的进程qq.exe为例 关键代码如下: function CheckTask(ExeFileName: string): Boo ...

  10. A Tour of Go Mutating Maps

    Insert or update an element in map m: m[key] = elem Retrieve an element: elem = m[key] Delete an ele ...