#include<iostream>
#include<stdio.h>
#define MaxSize 10
using namespace std;
typedef struct {
int data[MaxSize]= {1,2,4,6,7,9};
int length=6;
} SqList;
typedef struct {
int a[MaxSize];
int length;
} Temp;
typedef struct {
int data[MaxSize];
int length;
} Kill;
bool Inser_x(SqList &L,int x) {
int left=0,right=L.length-1,mid;
int Temp;
while(left<=right){
mid= (right+left)/2;
if(L.data[mid] == x){
Temp = L.data[mid];
L.data[mid] = L.data[mid+1];
L.data[mid+1] = Temp;
break;
}
else if(L.data[mid]<x){
left=mid+1;
}else{
right=mid-1;
}
}
if(left>right){
for(int i=L.length;i>right;i--){
L.data[i+1]=L.data[i];
L.data[i+1]=x;
}
}
return true;
}
int main(){
Temp T;
SqList L;
Kill R;
int x =6;
for(int k=0; k<L.length; k++) {
printf("%d",L.data[k]);
}
printf("\n");
if(Inser_x(L,x)){
for(int o=0; o<L.length; o++) {
printf("%d",L.data[o]);
}
printf("\n");
printf("%d",L.length);
}
return 0;
}
文章来源地址https://www.toymoban.com/news/detail-421510.html
文章来源:https://www.toymoban.com/news/detail-421510.html
到了这里,关于2023王道数据结构P18.9的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!