线性表删查改

这种代码我也是在是不好去说思路。

需要注意的可能就只有两点:

一、注意的可能是不要忘记长度增加或者删除;

二、输入的位置是否合法。

贴上水代码:

//
//  main.cpp
//  线性表的查改删
//  CCUT MALKER
//  Created by MaLker on 2017/3/17.
//  Copyright © 2017年 MaLker. All rights reserved.
//

#include <iostream>
#include <algorithm>
#define Max_Size 10000
using namespace std;
int Max_Lenth,Lenth,a[Max_Size];

void Creat_Arr(void){//数组创造函数//
    printf("Plese enter the Max length :");
    scanf("%d",&Max_Lenth);
    printf("Please Enter the Initial length :");
    scanf("%d",&Lenth);
    for (int i=0; i<Lenth; i++) {
        scanf("%d",&a[i]);
    }
}

void Find_aK(void){//查找K位数//
    int k;
    printf("Please Enter the sit which you want see");
    scanf("%d",&k);
    if (k>Lenth-1) {
        printf("Are You Kidding Me?\n");
        return ;
    }
    printf("a[%d] = %d\n",k,a[k-1]);
}

void Delet_Ksit_Number(void){//删除K位置上的数字//
    printf("Please int the Sit Which you want delete : ");
    int k;
    scanf("%d",&k);
    if (k>Lenth||k<=0) {
        printf("Are you sure?\n");
        return ;
    }
    for (int i=k; i<Lenth; i++) {
        a[i-1]=a[i];
    }
    Lenth--;
}

void Output_Arr(void){//数组输出
    for (int i=0; i<Lenth; i++) {
        printf("%3d",a[i]);
    }
    printf("\n");
    printf("Lenth = %d\n",Lenth);
}

void InSert_aK(void){//插入操作//
    if (Lenth+1>Max_Lenth) {
        printf("Illegal operation\n");
        return ;
    }
    int k;
    printf("Please input the sit which you want to Inser number :");
    scanf("%d",&k);
    for (int i=Lenth; i>=k-1; i--) {
        a[i]=a[i-1];
    }
    int num;
    printf("Please inter the number :");
    scanf("%d",&num);
    a[k-1]=num;
    Lenth++;
    printf("Succes!!\n");
}
void Operat(void){
    int Operat_Signal;
    printf("************************       WECLOE!!    *******************\n");
    while (true) {
        printf("Plsase input Operation code\n");
        printf("1: Creat a new Arr\n2:Dele a[k]\n3:Insert a new number\n4:Find ak\n5:Output Arr\n0:SHUT DOWN\n");
        scanf("%d",&Operat_Signal);
        switch (Operat_Signal) {
            case 1:
                Creat_Arr();
                break;
            case 2:
                Delet_Ksit_Number();
                break;
            case 3:
                InSert_aK();
                break;
            case 4:
                Find_aK();
                break;
            case 5:
                Output_Arr();
                break;
            default:
                break;
        }
        if (Operat_Signal==0) {
            break;
        }
    }
}


int main(int argc, const char * argv[]) {
    Operat();
    return 0;
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值