c++实现线性表增删改查

为什么80%的码农都做不了架构师?>>>   hot3.png

#include 
#include 
#include 
#define MAX_SIZE 100
using namespace std;

typedef struct SqList{
    int *elem;
    int length;
};
int Init_List(SqList *L);
int Insert_List(SqList *L,int ele,int num);
int Delete_List(SqList *L,int num);
void Display_List(SqList L);
int Append_List(SqList *L,int ele);
int Chanege_List(SqList *L,int ele,int num);
int Find_List(SqList *L,int num);
int main()
{
    SqList L1;
    int a;
    Init_List(&L1);
    cout<<"---append---"<elem = new int [MAX_SIZE];
    if(!L->elem) {return -1;}
    L->length = 5;
    for(int i=0;ilength;i++){
        L->elem[i] = i;
    }
    return 1;
}
/*=====追加=====*/
int Append_List(SqList *L,int ele){
    int i,j;
    L->length++;
    L->elem[L->length-1] = ele;
}
/*=====删除=====*/
int Delete_List(SqList *L,int num){
    printf("\dlete...\n");
    int i,j;
    for(i=num-1;i<=L->length;i++){
        L->elem[i]=L->elem[i+1];
    }
    L->length = L->length - 1;
    printf("insert %d is OK...\n\n\n");
}
/*=====修改=====*/
int Chanege_List(SqList *L,int ele,int num){
    L->elem[num] = ele;
}
/*=====查询=====*/
int Find_List(SqList *L,int num){
    cout<<"L"<<"["<elem[num-1]<length = L->length + 1;
    for(i=L->length;i>=num;i--){
        L->elem[i-1]=L->elem[i-2];
    }
    L->elem[num-1] = ele;
    printf("insert %d is OK...\n\n\n",ele);
}

/*=====显示=====*/
void Display_List(SqList L){
    printf("===display===\n");
    for(int i=0;i

 

转载于:https://my.oschina.net/lafter/blog/901760

你可能感兴趣的:(c++实现线性表增删改查)