表的实现(顺序)一
来源:互联网 发布:m1216nfh 网络扫描 编辑:程序博客网 时间:2024/06/15 15:57
SeqList.h:
- /*=============================================================================
- #
- # Author: liangshu - cbam
- #
- # QQ : 756029571
- #
- # School : 哈尔滨理工大学
- #
- # Last modified: 2015-10-27 20:03
- #
- # Filename: 顺序栈实现 - 副本.cpp
- #
- # Description:
- # The people who are crazy enough to think they can change the world, are the ones who do !
- =============================================================================*/
- #
- using namespace std;
- const int Dafultsize = 10;
- enum Error_code{success, overflow, underflow, Range_error};
- template<class List_entry>
- class List{
- public:
- List(int Size = Dafultsize):Max_list(Size), num(0){
- Entry = new List_entry[Max_list];
- }
- int Size_list()const;
- bool Full_list()const;
- bool Empty_list()const;
- void Clear();
- void Print_list()const;
- void Tra_list(void (*visit)(List_entry &));
- Error_code retrieve(int postion, List_entry &item)const;
- Error_code Replace(int postion, const List_entry &item);
- Error_code Remove(int postion, List_entry &item);
- Error_code Insert(int postion, const List_entry &item);
- ~List(){
- delete []Entry;
- }
- protected:
- int num;
- List_entry *Entry;
- int Max_list;
- };
- template<class List_entry>
- int List<List_entry>::Size_list()const{
- return num ;
- }
- template<class List_entry>
- bool List<List_entry>::Full_list()const{
- return num == Max_list - 1;
- }
- template<class List_entry>
- bool List<List_entry>::Empty_list()const{
- return num == 0;
- }
- template<class List_entry>
- void List<List_entry>::Clear(){
- num = 0;
- }
- template<class List_entry>
- Error_code List<List_entry>::Insert(int position, const List_entry &item){
- if(Full_list()){
- return overflow;
- }
- if(position < 0 || position > num){
- return Range_error;
- }
- for(int i = num - 1; i >= position; i--){
- Entry[i + 1] = Entry[i];
- }
- Entry[position] = item;
- num++;
- return success;
- }
- template<class List_entry>
- void List<List_entry>::Tra_list(void(*visit)(List_entry &)){
- for(int i = 0; i < num; i++){
- (*visit)(Entry[i]);
- }
- }
- template<class List_entry>
- Error_code List<List_entry>::retrieve(int position, List_entry &item)const{
- if(Full_list()){
- return underflow;
- }
- if(position < 0 || position > num){
- return Range_error;
- }
- item = Entry[position];
- return success;
- }
- template<class List_entry>
- Error_code List<List_entry>::Replace(int position, const List_entry &item){
- if(position > num || position < 0){
- return Range_error;
- }
- Entry[position] = item;
- return success;
- }
- template<class List_entry>
- Error_code List<List_entry>::Remove(int position, List_entry &item){
- if(Empty_list()){
- return underflow;
- }
- if(position < 0 || position > num){
- return Range_error;
- }
- item = Entry[position];
- for(int i = position;i < num; i++){
- Entry[i] = Entry[i + 1];
- }
- num--;
- return success;
- }
- template<class List_entry>
- void List<List_entry>::Print_list()const{
- cout<<"| ";
- for(int i = 0; i < num; i++){
- cout<<Entry[i];
- if(i != num - 1){
- cout<<" -- ";
- }
- }
- cout<<" |"<<endl;
- }
Test.cpp:
- #include<iostream>
- #include"a.h"
- using namespace std;
- int main()
- {
- List<int>list_1(9);
- for(int i = 1; i <= 5; i++){
- list_1.Insert(i - 1, i);
- }
- int x;
- list_1.Print_list();
- cout<<list_1.Size_list()<<endl;
- list_1.retrieve(1, x);
- cout<<x<<endl;
- list_1.Replace(2, 100);
- list_1.Print_list();
- list_1.Remove(3, x);
- list_1.Print_list();
- list_1.Clear();
- list_1.Print_list();
- return 0;
- }
0 0
- 表的实现(顺序)一
- 线性表的实现(一)顺序存储结构
- 数据结构(一)---顺序表的实现---java版
- 实验一:顺序表的实现
- 实验一顺序表的实现
- 实验一顺序表的实现
- 栈的实现(一)顺序栈
- 数据结构(一):线性表的顺序存储结构-顺序表的实现
- 顺序栈的实现一
- 队列的实现(一)顺序队列的实现
- 实验一 顺序表实现
- 线性表系列(一)-顺序表的详解与实现
- 实验一:线性表实验-顺序表的实现
- 实验一 线性表的顺序表示与实现
- 顺序栈的实现 C语言版(一)
- 十、队列的实现方法一(顺序表的复用)
- 【python】python数据结构(一)——线性表:顺序表的实现
- 一、(1)C++ 实现简单的线性表(顺序存储结构)
- .net 响应form请求
- 图片像素、大小、分辨率的关系
- 链式表的实现
- js中字符串String中使用正则表达式的方法
- Canvas画布
- 表的实现(顺序)一
- 字符集处理
- 链式队列实现完整版
- 欢迎使用CSDN-markdown编辑器
- Extjs tree节点的点击事件
- 2016.7.11 雏鹰
- 二、八、十、十六进制之间的转换
- 在ubuntu下安装pycharm。
- 安装包位置