数据结构:线性表插入一次删除一次的代码

#include <iostream>

#include <cmath>

#include <cstring>

#include <algorithm>

#include <stack>

#include <queue>

#include <cstdio>

using namespace std;

int insertsqlist(int weizhi,double charu,int *t,double b[])
{
    int n=*t,i;
    if(weizhi<1||weizhi>n+1)
        return 0;
    else
    {
        for(i=n+1;i>weizhi;i--)
            b[i]=b[i-1];
        b[weizhi]=charu;
        *t=++n;
        return 1;
    }

}

int desertsqlist(int weizhi,int *t,double b[])
{
    int n=*t,i;
    if(weizhi<1||weizhi>n)
        return 0;
    else
    {
        for(i=weizhi;i<n;i++)
            b[i]=b[i+1];
        *t=--n;
        return 1;
    }

}

double a[100],charu;

int main()
{
    int n,weizhi,i,total;
    while(cin>>n)
    {
        total=n;
        printf("请输入%d个数",n);
        for(i=1;i<=n;i++)
            cin>>a[i];
        printf("please enter the weizhi where you would like to set:");
        cin>>weizhi;
        printf("please enter the num that you would like to set:");
        cin>>charu;
        int m=insertsqlist(weizhi,charu,&total,a);
        if(m==1)
        {
            for(i=1;i<=total;i++)
                cout<<a[i]<<"    ";
            printf("\n");
        }
        else
            printf("SB!插入你个鸡巴!\n");
        printf("please enter the weizhi where you would like to delete:");
        cin>>weizhi;
        m=desertsqlist(weizhi,&total,a);
        if(m==1)
        {
            for(i=1;i<=total;i++)
                cout<<a[i]<<"    ";
            printf("\n");
        }
        else
            printf("SB!删除你个鸡巴!\n");
    }
    return 0;
}

posted @ 2014-07-17 09:48  最爱夏朵朵  阅读(197)  评论(0编辑  收藏  举报