📄 2.11.cpp
字号:
#include <iostream.h>
#define INIT_SIZE 10
typedef int ElemType;
typedef struct
{
ElemType* array;
int ListSize;
int Length;
}Sqlist;
void init_list(Sqlist& L);
bool insert_list(Sqlist& L,const ElemType item);
void display_list(const Sqlist L);
int main()
{
Sqlist L;
init_list(L);
for(int i=0; i<=9; i++)
{
int current = rand()%100;
cout << current << ' ';
insert_list(L,current);
}
cout << endl;
display_list(L);
system("pause");
return 0;
}
void init_list(Sqlist& L)
{
L.ListSize = INIT_SIZE;
L.Length = 0;
L.array = (ElemType*)malloc(INIT_SIZE*sizeof(ElemType));
}
bool insert_list(Sqlist& L,const ElemType item)
{
int temp = 0;
if(L.Length == L.ListSize)
return false;
for(; temp<=L.Length-1; temp++)
if(item <= L.array[temp])
break;
for(int i=L.Length-1; i>=temp; i--)
L.array[i+1] = L.array[i];
L.array[temp] = item;
L.Length++;
return true;
}
void display_list(const Sqlist L)
{
if(L.Length == 0)
;
for(int i=0; i<=L.Length-1; i++)
cout << L.array[i] << ' ';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -