zoukankan      html  css  js  c++  java
  • 线性表的顺序存储

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <stdlib.h>
    #include <string.h>
    #include <iomanip>
    #define N 500010
    #define INF 10000000
    #define LL long long
    #define eps 10E-9
    #define mem(a)  memset(a,0,sizeof(a))
    #define w(a)   while(a)
    #define s(a)   scanf("%d",&a)
    #define ss(a,b)   scanf("%d%d",&a,&b)
    #define sss(a,b,c)   scanf("%lld%lld%lld",&a,&b,&c)
    #define MAXN 9999
    #define MAXSIZE 10
    #define DLEN 4
    #define MAXN 9999
    #define MAXSIZE 10
    #define DLEN 4
    using namespace std;
    struct mylist//仅仅一个结构体  和数组几乎相同。。


    {
        int data[MAXN];//存数据
        int length;//数据个数
    } node;
    void myinsert(int pos, int cnt)
    {
        for(int i = node.length ; i>=pos; i--)
        {
            node.data[i+1] = node.data[i];
        }
        node.data[pos]=cnt;
        node.length++;
        cout<<"success!"<<endl;
        for(int i=1; i<=node.length; i++)
        {
            cout<<node.data[i]<<" ";
        }
        cout<<endl;
    }
    void mydelete(int pos)
    {
        for(int i=pos; i<node.length; i++)
        {
            node.data[i]=node.data[i+1];
        }
        node.length--;
        cout<<"success!"<<endl;
        for(int i=1; i<=node.length; i++)
        {
            cout<<node.data[i]<<" ";
        }
        cout<<endl;
    }
    void myquery(int pos)
    {
        cout<<node.data[pos]<<endl;
    }
    int main()
    {
        int num;
        printf("input the length of data ");
        cin>>num;
        node.length=num;
        cout<<"input all the data"<<endl;
        for(int i=1; i<=num; i++)
        {
            cin>>node.data[i];
        }
        int pos, cnt;
        cout<<"input the postion and data of insert"<<endl;
        cin>>pos>>cnt;
        myinsert(pos, cnt);
        cout<<"input the  postion of the data you want to dalete"<<endl;
        cin>>pos;
        mydelete(pos);
        cout<<"input the  postion of the data you want to query"<<endl;
        cin>>pos;
        myquery(pos);
        return 0;
    }

  • 相关阅读:
    QString::toStdString() crashes
    Consolas 字体
    Mesh BRep Shapes
    PyOpenCL库安装
    全国精确到乡镇的行政边界、路网水系建筑poi等矢量shp免费下载
    DEM数据(ASTER GDEM|SRTM|GLS2005|ALOS DEM)下载
    IDL基础
    辐射定标与FLAASH大气校正
    Circos绘图—基础
    R-散点密度图
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/6928229.html
Copyright © 2011-2022 走看看