/*
** File name: SeqList.h
** Author: ZhouFeng
** Date: 2012/03/25
*/
#ifndef SEQ_LIST_H
#define SEQ_LIST_H
#define MAX_SIZE 100
#define ERROR 0
#define SUCCESS 1
typedef int EleType;
typedef struct SeqList
{
EleType _seqList[MAX_SIZE];
int length;
}SeqList;
void InitSeqList(SeqList *L);
int InsertEle(SeqList *L, int index, EleType data);
int DeleteEle(SeqList *L, int index, EleType *data);
int GetEle(SeqList *L, int index, EleType *data);
int GetSeqListLength(SeqList *L);
#endif
/*
** File name: SeqList.c
** Author: ZhouFeng
** Date: 2012/03/25
*/
#include <stddef h="">
#include "SeqList.h"
void InitSeqList(SeqList *L)
{
if(L == NULL)
{
return;
}
L->length = 0;
}
int InsertEle(SeqList *L, int index, EleType data)
{
int i = 0;
if(L == NULL && (index < 0 && index > L->length - 1)
|| L->length >= MAX_SIZE)
{
return ERROR;
}
/* insert a new element front of 'index'*/
for(i = L->length - 1; i > index - 1; --i)
{
(L->_seqList)[i + 1] = (L->_seqList)[i];
}
(L->_seqList)[index] = data;
++L->length;
return SUCCESS;
}
int DeleteEle(SeqList *L, int index, EleType *data)
{
int i = 0;
if(L == NULL && index < 0 && index > L->length - 1
&& data == NULL && L->length <= 0)
{
return ERROR;
}
*data = (L->_seqList)[index];
for(i = index; i < L->length; ++i)
{
(L->_seqList)[i] = (L->_seqList)[i + 1];
}
--L->length;
return SUCCESS;
}
int GetEle(SeqList *L, int index, EleType *data)
{
if(L == NULL && index < 0 && index > L->length - 1)
{
return ERROR;
}
*data = (L->_seqList)[index];
return SUCCESS;
}
int GetSeqListLength(SeqList *L)
{
return L->length;
}
</stddef>
#include <stdio h="">
#include <stdlib h="">
#include "SeqList.h"
/* Print */
void PrintSeqList(SeqList *L)
{
int i = 0;
for(i = 0; i < L->length; )
{
printf("%4d", (L->_seqList)[i]);
++i;
if(i % 5 == 0)
{
printf("\n");
}
}
}
int main(int argc, char* argv[])
{
int i = 0;
SeqList L;
srand((unsigned long)time());
InitSeqList(&L);
for(i = 0; i < MAX_SIZE; ++i)
{
InsertEle(&L, 0, rand() % 30);
}
PrintSeqList(&L);
return 0;
}
</stdlib></stdio>
分享到:
相关推荐
初学数据结构,顺序表的增删改查自己还不是很熟练,将自己的学习记录在CSDN社区。希望在编程道路的小伙伴共同进步
数据结构C++顺序表SeqList类的定义
顺序表初始化void Init(SeqList* psl); 检查空间,如果满了,进行增容void CheckCapacity(SeqList* psl); 顺序表尾插void PushBack(SeqList* psl,DateType x); 顺序表尾删void PopBack(SeqList* psl); 顺序表头插...
SeqList <T>::SeqList(int listMaxSize) //初始化顺序表 { if(listMaxSize>0){ ListMaxSize=listMaxSize; Length=0; Mylist=new T [ListMaxSize]; // 创建连续的表空间 } } template SeqList <T>::~...
实现提示: 首先定义顺序表的数据类型——顺序表类SeqList,包括题目要求的插入、删除、查找 等基本操作,为便于查看操作结果,设计一个输出函数依次输出顺序表的元素。 const int MaxSize=10; template <class T> ...
*输 入:顺序表信息的数组形式a[],顺序表长度n *前置条件:顺序表不存在 *功 能:将数组a[]中元素构建为长度为n的顺序表 *输 出:无 *后置条件:顺序表的长度取零及空间最大值有了新值。 */ template ...
1)定义顺序表类模板,例如SeqList,封装顺序表的基本操作算法; 2)在主函数中定义对象,并调用成员函数,验证顺序表的基本操作。 2.适用人群: 数据结构与算法初学者;C++编译基本掌握 3.使用场景: 数据结构与...
数据结构实验源码+顺序表的基本操作,*.doc单链表的基本操作,叉树的基本操作,图的基本操作C++语言 勾月科技www.gouyue.net
//顺序表容量 int size; //顺序表元素数量 int* base; //指向动态内存分配的指针 }Seqlist; Seqlist* init_list(Seqlist* list) { list->capacity = Seqlist_initsize; list->size = 0; list->base = (int*)...
数据结构顺序表 SeqList.h 头文件代码如下: #pragma once //防止头文件被二次引用 #include<stdio.h> /*perror, printf*/ #include<assert.h> /*assert*/ #include<stdlib.h> /*realloc*/ typedef int ...
数据结构(顺序表和单链表)C++实现 我在自学数据结构,代码是我自己写的,水平有限。
数据结构C#版笔记--顺序表(SeqList)
本工程实现了严蔚敏 《数据结构 C语言》中顺序表的实现以及常用的操作。包括顺序表的初始化、销毁、求表长、查找、查询前驱节点、查询后继节点、插入、删除、遍历、打印等功能。并且写了测试代码,对每个函数都做了...
实验1-顺序表.cpp
#include using namespace std; const int MaxSize=10; template class SeqList { public: SeqList(){length=0;... SeqList(T a[],int n);... ~SeqList(){}//析构函数 ...//顺序表的长度 }; 。。。。。
建立一有序的顺序表,并实现下列操作: 把元素x插入表中并保持有序;2.查找值为x的元素,若找到将其删除; 3.输出表中各元素的值。 算法思想: 相关函数 void main();//主函数 int InsList(SeqList *L,ElemType x);/...
本文实例讲述了C#数据结构之顺序表(SeqList)实现方法。分享给大家供大家参考,具体如下: 线性结构(Linear Stucture)是数据结构(Data Structure)中最基本的结构,其特征用图形表示如下: 即:每个元素前面有且只有...
用C++编写的顺序表基本操作 #include "stdafx.h" #include "iostream" using namespace System; using namespace std; const int Max=10; class seqList {int data[Max]; int i,last; public: seqList(int x[],int...
使用c++实现的顺序表:多文件编程,层次清晰,函数有注释 SeqList();//构造函数,存储的元素个数设为0 bool setLength(size_t length);//设置已经存储的元素个数 bool addElement(ElemType element);//把某个...
//程序主要实现顺序表的建立和插入 //author by Bin_Yang //time at 2009-9-28 /////////////////////////////////////////////////////////////////////////////// #define MAXSIZE 100 #include #include ...