您的位置:首页 > 房产 > 建筑 > 北京网站seo哪家公司好_当当网网站建设方案_如何免费搭建自己的网站_线上推广的好处

北京网站seo哪家公司好_当当网网站建设方案_如何免费搭建自己的网站_线上推广的好处

2025/5/3 23:56:05 来源:https://blog.csdn.net/2403_87165176/article/details/143958622  浏览:    关键词:北京网站seo哪家公司好_当当网网站建设方案_如何免费搭建自己的网站_线上推广的好处
北京网站seo哪家公司好_当当网网站建设方案_如何免费搭建自己的网站_线上推广的好处

文章目录

  • 概念及结构
  • 接口实现

概念及结构

顺序表是用一段物理地址连续的存储单元依次存储数据元素的线性结构,一般情况下采用数组存
储。在数组上完成数据的增删查改

顺序表一般分为两种

静态:使用定长数组存储元素
动态:使用动态开辟的数组存储

在这里插入图片描述

#include <stdio.h>
#define N 10000
int main()
{typedef int SLdatetype;struct Seqlist {int a[N];int size;};return 0;
}

静态顺序表缺点:开多了用不了,开少了又不够

在这里插入图片描述

接口实现

头文件

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <iostream>typedef int SLdatetype;
#define int_capacity 4typedef	struct Seqlist{SLdatetype* array;size_t size;size_t capacity;}SL;void SLInit(SL* ps);//顺序表初始化
void checkcapacity(SL* ps);//检查空间大小,扩容void seqlistpushback(SL* ps,SLdatetype x);//尾插
void seqlistpopback(SL* ps);//尾割void seqlistpushfront(SL* ps,SLdatetype x);//头插
void seqlistpopfront(SL* ps);//头割SLdatetype seqlistfind(SL* ps, SLdatetype x);//查找xvoid seqlistinsert(SL* ps, SLdatetype pop,SLdatetype x);//在pop位置插入x
void seqlistrelease(SL* ps, SLdatetype pop);//在pop位置删除xvoid destory(SL* ps);//摧毁顺序表
void seqlistprint(SL* ps);//打印顺序表

函数实现

#include "seqlist.h"
void SLInit(SL* pch)
{pch->array = (SLdatetype*)malloc(sizeof(SLdatetype) * int_capacity);assert(pch);pch->size = 0;pch->capacity = int_capacity;
}
void destroy(SL* pch)
{free(pch->array);pch->array = NULL;pch->size = pch->capacity = 0;
}
void checkcapacity(SL* pch)
{if (pch->size == pch->capacity){SLdatetype* tmp = (SLdatetype*)malloc(sizeof(SLdatetype) * pch->capacity * 2);assert(tmp);pch->array = tmp;}pch->capacity *= 2;
}
void seqlistpushback(SL* pch, SLdatetype x){checkcapacity(pch);pch->array[pch->size++] = x;
}void seqlistpopback(SL* pch)
{assert(pch->size>0);pch->size--;
}
void seqlistprint(SL* pch)
{assert(pch);for (int i = 0;i < pch->size;i++){printf("%d ", pch->array[i]);}printf("\n");
}
void seqlistpushfront(SL* pch, SLdatetype x)
{assert(pch);checkcapacity(pch);int end = pch->size - 1;while (end>=0){pch->array[end+1] = pch->array[end];end--;}pch->array[0] = x;pch->size++;
}
void seqlistinsert(SL* pch, int pop, SLdatetype x)
{assert(pch);checkcapacity(pch);int end = pch->size - 1;while (end>=pop){pch->array[end + 1] = pch->array[end];end--;}pch->array[pop] = x;pch->size++;
}
void seqlistpopfront(SL* pch)
{assert(pch);int end = 0;while (end < pch->size-1){   pch->array[end] = pch->array[end+1];}pch->size--;
}
SLdatetype seqlistfind(SL* pch, SLdatetype x)
{assert(pch);for (int i = 0;i < pch->size;i++){if (pch->array[i] == x){return i;}}return -1;
}void seqlistrelease(SL* pch, SLdatetype pos)
{assert(pch);int end = pch->size - 1;int j = pos;while (j<end){pch->array[j] = pch->array[j + 1];j++;}pch->size--;
}

测试

#include "seqlist.h"
int main()
{SL s;SLInit(&s);seqlistpushback(&s, 1);seqlistpushback(&s, 2);seqlistpushback(&s, 3);seqlistpushback(&s, 4);seqlistpushback(&s, 5);seqlistpushback(&s, 6);seqlistpushback(&s, 7);seqlistprint(&s);seqlistpopback(&s);seqlistpopback(&s);seqlistpopback(&s);seqlistpopback(&s);seqlistprint(&s);seqlistpopback(&s);seqlistpushback(&s, 10);seqlistpushback(&s, 20);seqlistprint(&s);seqlistinsert(&s,2,9);seqlistprint(&s);seqlistpushfront(&s, 10);seqlistprint(&s);seqlistrelease(&s, 0);seqlistprint(&s);int c = seqlistfind(&s, 9);printf("%d", c);return 0;
}

在这里插入图片描述

生死有命富贵在天,能不能悟就看自己了

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com