#include<bits/stdc++.h>
using namespace std;
#define Max 50
struct SqList{
int a[Max]={2,3,4,5,6,7,1,9};
int length= 8;
};
bool listdelete(SqList &s,int &elem){
if(s.length==0){
return false;
}
int minn=s.a[0];
int flag= 0;
for(int i=1;i<s.length;i++){
if(s.a[i]<minn){
minn=s.a[i];flag=i;
}
}
elem=s.a[flag];
s.a[flag]=s.a[s.length-1];
return true;
}
int main(){
SqList s;
cout<<"原来的线性表:"<<endl;
for( int i=0;i<s.length;i++) cout<<s.a[i]<<" ";
cout<<endl;
int k=0;
if(listdelete(s,k)){
cout<<"最小元素k=" <<k<<endl;
cout<<"修改之后的线性表为:"<<endl;
for(int i=0;i<s.length;i++){
cout<<s.a[i]<<" ";
}
cout<<endl;
}else{
cout<<"错误"<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define Max 50
struct SqList{
int a[Max]={1,2,3,4,5,6,7};
int length=8;
};
void reverse(SqList &L){
for(int i =0;i<=L.length/2;i++){
int v= L.a[i];
L.a[i]=L.a[L.length-1-i];
L.a[L.length-i-1]=v;
}
}
int main(){
SqList L;
for (int i = 0; i < L.length; i++)cout<<L.a[i]<<" ";
cout<<"逆置之后的数组的值"<<" ";
reverse(L);
for (int i = 0; i <L.length; i++) cout<<L.a[i]<<" ";
return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define Max 50
struct SqList{
int a[Max]={5,2,0,1,3,1,4,1,4,1,4};
int length= 11;
};
bool deletelist(SqList &L,int x){
int k=0;
for (int i = 0; i < L.length; i++)
{
if(L.a[i]==x) k++;
else L.a[i-k]=L.a[i];
}
L.length=L.length-k;
}
int main(){
SqList L;
for (int i = 0; i < L.length; i++)
{
cout<<L.a[i]<<" ";
}
cout<<endl;
deletelist(L,1);
for (int i = 0; i < L.length; i++)
{
cout<<L.a[i]<<" ";
}
cout<<endl;
return 0;
}
bool deletesq(sqlist &L, int s,int v){
if(L.length==0||s>=v) return false;
int k=0;
bool flag = false;
for (int i = 0; i < L.length; i++)
{
if(L.a[i]>=s){
flag = true;break;
}
}
if(!flag)return false;
for (int i = 0; i < L.length; i++)
{
if(L.a[i]>=s&&L.a[i]<=v) k++;
else L.a[i-k]=L.a[i];
}
L.length= L.length-k;
return true;
}
|