标签:ios sql printf for 遍历 false init 打印 efi
#include<stdio.h>
#include<iostream>
#define MaxSize 10
using namespace std;
typedef struct //定义顺序表结构体
{
int data[MaxSize];
int length;
} SqList;
//顺序表初始化函数
void InitSqList(SqList &sqList)
{
sqList.length = 0;
int a[10] = {1,2,3,4,5,6,7,8,9,10};
for(int i = 0; i < MaxSize; i++)
{
sqList.data[i] = a[i];
sqList.length ++;
}
}
//删除第i个元素(注意这里是第i个位置)此元素用e带回
bool ListDelete(SqList &sqList,int i,int &e)
{
if(i < 1||i > sqList.length)
{
return false;
}
e = sqList.data[i-1];
for(int j = i; j < sqList.length; j++)
{
sqList.data[j-1] = sqList.data[j];
}
sqList.length--;
return true;
}
//在第i个位置插入元素(注意这里是第i个位置)
bool ListInsert(SqList &sqList,int i,int e)
{
if(i < 1||i > sqList.length||sqList.length >= MaxSize)
{
return false;
}
for(int j = sqList.length; j > i; j--)
{
sqList.data[j] = sqList.data[j-1];
}
sqList.data[i-1] = e;
sqList.length ++;
return true;
}
//打印顺序表
void printSqList(SqList sqList)
{
for(int i = 0; i < sqList.length; i++)
{
printf("%d\n",sqList.data[i]);
}
}
int main()
{
SqList sqList;
printf("执行初始化函数\n");
InitSqList(sqList);
printf("初始化函数完成\n");
printf("初始长度为%d\n",sqList.length);
printf("打印顺序表\n");
printSqList(sqList);
printf("验证删除超出范围\n");
int e;
if(ListDelete(sqList,11,e))
{
printf("e为%d\n",e);
}
else
{
printf("删除失败\n");
}
printf("验证删除成功\n");
if(ListDelete(sqList,9,e))
{
printf("e为%d\n",e);
printf("打印顺序表\n");
printSqList(sqList);
}
else
{
printf("删除失败\n");
}
printf("验证插入超出范围\n");
if(ListInsert(sqList,11,9))
{
printf("e为%d\n",e);
}
else
{
printf("插入失败\n");
}
printf("验证插入成功\n");
if(ListInsert(sqList,9,9))
{
printf("e为%d\n",e);
printf("打印顺序表\n");
printSqList(sqList);
}
else
{
printf("插入失败\n");
}
}
标签:ios sql printf for 遍历 false init 打印 efi
原文地址:https://www.cnblogs.com/coderlixingyun/p/13681691.html