#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. Beginning Android 4 Programming Book学习

    Chapter 3 EditText不自动获取焦点,自动获取焦点但不显示软键盘  Page 122-123 只有定义了android:id属性的控件在屏幕翻转后状态才会被持久化  Page 133 C ...

  2. hbase shell下如何使用删除键

    今天刚安装好了hbase,通过Secure CRT登录hbase shell,敲入错误命令无法使用删除键(Backspace或是Ctrl+Backspace都不管用)删除,后来在终端-->仿真下 ...

  3. 《深入Java虚拟机学习笔记》- 第10章 栈和局部变量操作

    Java栈和局部变量操作 Java虚拟机是基于栈的机器,几乎所有Java虚拟机的指令都与操作数栈相关.栈操作包括把常量压入操作数栈.执行通用的栈操作.在操作数栈和局部变量之间往返传输值. 1常量入栈操 ...

  4. e2e 自动化集成测试 架构 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step (二) 图片验证码的识别

    上一篇文章讲了“e2e 自动化集成测试 架构 京东 商品搜索 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step 一 京东 商品搜索 ...

  5. 【转】为什么C++编译器不能支持对模板的分离式编译

    出处:刘未鹏(pongba) http://blog.csdn.net/pongba)   首先,一个编译单元(translation unit)是指一个.cpp文件以及它所#include的所有.h ...

  6. 【HTML】Advanced7:Embedded Content: Video, Audio, and Canvas

    1.video <video src="kitties.mp4" poster="fluffy.jpg"(display before video is ...

  7. uva 12296 Pieces and Discs

    题意: 有个矩形,左下角(0,0),左上角(L,W). 思路: 除了圆盘之外,本题的输入也是个PSLG,因此可以按照前面叙述的算法求出各个区域:只需把线段视为直线,用切割凸多边形的方法 :每次读入线段 ...

  8. 命令mv

    mv 文件 目标目录如果目标目录改成文件名,mv命令可用于重命名文件.

  9. Sort--冒泡排序

    冒泡排序 public class BubbleSort { public static void bubblesort(int[] a){ for(int i=0;i<a.length-1;i ...

  10. leetcode@ [199] Binary Tree Right Side View (DFS/BFS)

    https://leetcode.com/problems/binary-tree-right-side-view/ Given a binary tree, imagine yourself sta ...