#include<iostream>using namespace std;#define Initsize 100typedef int ElemType;typedef struct { ElemType *data; int MaxSize,length;}seqList;void Init(seqList *L){ L->data=https://bbs.csdn.net/topics/(ElemType *)malloc(sizeof(ElemType)*Initsize); L->length=0; L->MaxSize=Initsize;}void create(seqList *L,int n){ int i; for (i=0;i
#include<iostream>
using namespace std;
#define Initsize 100
typedef int ElemType;
typedef struct {
ElemType* data;
int MaxSize, length;
}seqList;
void Init(seqList* L)
{
L->data = (ElemType*)malloc(sizeof(ElemType) * Initsize);
L->length = 0;
L->MaxSize = Initsize;
}
void create(seqList* L, int n)
{
int i;
for (i = 0; i < n; i++)
{
cin >> (L->data[i]);
L->length = n;
}
}
void show(seqList L)
{
int i;
for (i = 0; i < L.length; i++)
{
cout << L.data[i] << ' ';
}
}
bool Del_Min(seqList* L, ElemType* value)
{
if (L->length == 0)
{
return false;
}
*value = L->data[0];
int pos = 0, i;
for (i = 1; i < L->length; i++)
{
if (L->data[i] < *value)
{
*value = L->data[i];
pos = i;
}
}
L->data[pos] = L->data[L->length - 1];
L->length--;
return true;
}
int main()
{
int n, value;
seqList L;
Init(&L);
cin >> n;
create(&L, n);
Del_Min(&L, &value);
show(L);
cout << endl;
return 0;
}
沒問題,可以洗掉一個最小值。
uj5u.com熱心網友回復:
你好歹把代碼捋清楚再給人看呀
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/183393.html
標籤:新手樂園
