zoukankan      html  css  js  c++  java
  • 顺序表的封装

    #include<iostream>
    typedef  int DataType;
    typedef  int Status;
    #define MaxSize 100
    typedef struct
    {
        DataType data[MaxSize];
        int length;
    }SeqList;
    #define TRUE 1
    #define FALSE 0
    #define OK 1
    #define ERROR 0
    using namespace std;
    class SList
    {
        SeqList S;
    public:
         SList()
        {
            S.length=0;
        }
         Status ClearList()
         {
             S.length=0;
             return OK;
         }
         Status EmptyList()
         {
             if(S.length)
             {
                 return FALSE;
             }
             else
                 return OK;
         }
         int ListLengh()
         {
             return S.length;
         }
         int Locate(DataType e)
         {
             for(int i=0; i<S.length; i++)
             {
                 if(S.data[i]==e)
                 {
                     return i+1;
                 }
             }
             return FALSE;
         }
         DataType GetData( int k)
         {
             if(k<1||k>S.length)
             {
                 return FALSE;
             }
             return S.data[k-1];
         }
         void InsList()
         {  
             while(1)
             {   
                 bool b;
                 int pos;
                 DataType e;
                 cout<<"请输入位置插入:"<<endl;
                 cin>>pos;
                 pos--;
                 if(pos>=0&&pos<=S.length)
                 {
                     cout<<"请输入插入元素的值:"<<endl;
                     cin>>e;
                     for(int i=S.length-1; i>=pos; i--)
                    {
                        S.data[i+1]=S.data[i];
                     }
                     S.data[pos]=e;
                     S.length++;
                     cout<<"Success"<<endl;
                     cout<<"是否继续插入:   "<<endl;
                     cout<<"是          1"<<endl;
                     cout<<"否          0"<<endl;
                     cin>>b;
                     if(!b)
                     {
                         break;
                     }
                }
                 else   cout<<"位置非法"<<endl;
            }
    };
         Status DelList(DataType &e)
         {
             while(1)
             {   
                 bool b;
                 int pos;
                 cout<<"请输入删除位置:"<<endl;
                 cin>>pos;
                 pos--;
                 if(pos>=0&&pos<=S.length-1)
                 {
                    e=S.data[pos];
                    for(int i=pos; i<S.length-1; i++)
                    {
                        S.data[i]=S.data[i+1];
                     }
                     S.length--;
                     cout<<"Success"<<endl;
                     cout<<"是否继续删除:   "<<endl;
                     cout<<"是          1"<<endl;
                     cout<<"否          0"<<endl;
                     cin>>b;
                     if(!b)
                     {
                         break;
                     }
                }
                else   cout<<"位置非法"<<endl;
            }
             return OK;
         }
    };
    int main()
    {
        return 0;
    }

  • 相关阅读:
    轻量级分布式任务调度框架(二、LTS编译、打包、部署)
    轻量级分布式任务调度框架(一、LTS简介、特点、工作流程)
    MySQL数据库学习一
    Navicat 连接 SQL Server 数据库,报错 08001
    noVNC 遇到一个错误: Uncaught TypeError: Cannot read property 'forEach' of undefined
    加强自己VPS服务器安全的一次经历
    Python 编码错误的本质和解决方案
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'data' at line 1
    requests爬虫请求报错:UnicodeEncodeError: 'latin-1' codec can't encode character 'u2026' in position 30
    docker无法删除镜像,Error: No such container,附docker常用命令
  • 原文地址:https://www.cnblogs.com/Howbin/p/8639387.html
Copyright © 2011-2022 走看看