zoukankan      html  css  js  c++  java
  • 实验1——顺序表例程

    Description

    实现顺序表的创建、插入、删除、查找

    Input

    第一行输入顺序表的实际长度n
    第二行输入n个数据
    第三行输入要插入的新数据和插入位置
    第四行输入要删除的位置
    第五行输入要查找的位置

    Output

    第一行输出创建后,顺序表内的所有数据,数据之间用空格隔开
    第二行输出执行插入操作后,顺序表内的所有数据,数据之间用空格隔开
    第三行输出执行删除操作后,顺序表内的所有数据,数据之间用空格隔开
    第四行输出指定位置的数据

    Sample Input

    6
    11 22 33 44 55 66
    888 3
    5
    2
    

    Sample Output

    11 22 33 44 55 66 
    11 22 888 33 44 55 66 
    11 22 888 33 55 66 
    22
    

    HINT

    第i个位置是指从首个元素开始数起的第i个位置,对应数组内下标为i-1的位置






    #include<stdio.h> #define MAX 100 int SeqList[MAX],len; void Insert(int pos,int value){ int i; for(i=len;i>=pos;i--) SeqList[i+1]=SeqList[i]; SeqList[pos]=value; len++; } void Del(int pos){ int i; for(i=pos;i<len;i++) SeqList[i]=SeqList[i+1]; len--; } void Output(){ int i; for(i=1;i<=len;i++) printf("%d ",SeqList[i]); printf("\n"); } int main(){ int pos,i,value; scanf("%d",&len); for(i=1;i<=len;i++) scanf("%d",&SeqList[i]); Output(); scanf("%d%d",&value,&pos); Insert(pos,value); Output(); scanf("%d",&pos); Del(pos); Output(); scanf("%d",&pos); printf("%d\n",SeqList[pos]); return 0; }
  • 相关阅读:
    2117 poj 割点练习
    hdu 2767强连通分量练习
    hdu 1301 kruskal 最小生成树
    hdu 1523 求割点和块
    hdu 1207Arbitrage 最短路劲
    hdu 1874 畅通工程续
    求最小点基 poj 1236
    Hdu 1301 prim算法 生成最小生成树
    我眼中的性能测试工程师
    Web系统的测试
  • 原文地址:https://www.cnblogs.com/suiyun/p/2690676.html
Copyright © 2011-2022 走看看