C语言数据结构--(线性表一)
来源:互联网 发布:php记事本编写软件 编辑:程序博客网 时间:2024/04/30 11:59
这里采用顺序存储的方式简单的实现线性表的插入和删除操作。
#include <stdio.h>
typedef int datatype; /*datatype可为任意类型,这里假设为int*/
#define maxsize 1024 /*线性表可能的最大长度,这里假设为1024*/
typedef struct SqList
{
datatype data[maxsize];
int length;
}SqList;
/*线性表的插入操作,在线性表的第i个位置插入一个新节点,使长度为n的线性表变成长度为n+1的线性表*/
int Line_Insert(SqList *L,datatype x,int i)
{
int j;
if (L->length == maxsize) /*表已满*/
{
printf("Overflow");
return NULL;
}
if (i < 1 || i > L->length+1)/*插入位置错误*/
{
printf("The location is error\n");
return NULL;
}
else
{
for (j = L->length - 1; j >= i-1; j--)
{
L->data[j+1] = L->data[j]; /*节点后移*/
}
L->data[i-1] = x;
L->length ++;
return 1;
}
}
/*线性表的删除操作*/
int Line_Delete(SqList *L,int i)
{
int j;
if ( i < 1 || i > L->length)
{
printf("The location error\n");
return NULL;
}
else
{
for ( j = i; j < L->length; j++) /*节点前移*/
{
L->data[i-1] = L->data[i];
}
L->length--;
return 1;
}
}
- C语言数据结构--(线性表一)
- 基于C/C++语言数据结构之线性表(一)
- 数据结构(C语言)线性表 -单链表
- 【数据结构】数据结构C语言的实现(线性表)
- 数据结构--线性表.顺序表(C语言实现)
- 数据结构 - 线性表之顺序表 (c 语言)
- 数据结构(c语言)线性表-顺序表
- 数据结构线性表各种结构代码实现(C语言)
- 基于C/C++语言数据结构之线性表(二)
- 数据结构 线性表的基本操作(C语言)
- 数据结构(C语言) 线性表 链式存储 单链表
- 数据结构(C语言) 线性表 链式存储 双链表
- 数据结构(C语言)线性表 顺序存储
- 线性表数据结构C语言实现
- C语言数据结构之线性表
- C语言数据结构之线性表
- C语言数据结构之线性表(续)
- 数据结构_1:线性表: C语言实现
- MFC 单击按钮弹出菜单
- Win7 CreateRemoteThread 另类使用方法
- IntelliJ Idea 常用快捷键列表
- TCP协议三次握手过程分析(转)
- MFC的图片按钮
- C语言数据结构--(线性表一)
- Python - "print()"函数 中 "%" 后面字母的意义
- window.location.href IE下无效问题
- nginx configure error: the HTTP rewrite module requires the PCRE library
- 改变控件大小和位置
- 【LeetCode】3Sum Closest
- 网站要怎么做才适合优化?
- Ubuntu出错笔记_libdl.so.2
- Chromium相关产品