Sqlist
来源:互联网 发布:淘宝全棉时代有假货吗 编辑:程序博客网 时间:2024/05/01 20:58
// SqList.cpp : 定义控制台应用程序的入口点。
//
//
#include "stdafx.h"
#include<iostream>
using namespace std;
#include<iostream>
using namespace std;
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
#define LIST_INIT_SIZE 100
#define LISTINCREAMENT 10
#define LISTINCREAMENT 10
struct ElemType
{
int data;
};
{
int data;
};
typedef struct
{
ElemType* elem;
int length;
int listSize;
}SqList;
{
ElemType* elem;
int length;
int listSize;
}SqList;
Status InitList_Sq(SqList& L);
Status ListInsert_Sq(SqList& L, int i, ElemType e);
Status ListDelete_Sq(SqList& L, int i, ElemType& e);
Status MergeList_Sq(SqList& La, SqList& Lb, SqList& Lc);
Status ListInsert_Sq(SqList& L, int i, ElemType e);
Status ListDelete_Sq(SqList& L, int i, ElemType& e);
Status MergeList_Sq(SqList& La, SqList& Lb, SqList& Lc);
//展示结果
Status ShowList(SqList& L);
Status ShowList(SqList& L);
int main()
{
SqList La,Lb,Lc;
InitList_Sq(La);
InitList_Sq(Lb);
InitList_Sq(Lc);
ElemType e1, e2, e3, e4, e5, e6,tempE;
e1.data = 1;
e2.data = 2;
e3.data = 3;
e4.data = 4;
e5.data = 5;
e6.data = 6;
tempE.data = 0;
ListInsert_Sq(La, 1, e1);
ListInsert_Sq(La, 2, e2);
ListInsert_Sq(La, 3, e3);
ListInsert_Sq(La, 4, e4);
ListInsert_Sq(La, 5, e5);
ListInsert_Sq(La,3, e6);
ShowList(La);
ListDelete_Sq(La, 5, tempE);
ShowList(La);
cout << "\n" << tempE.data<<"\n";
{
SqList La,Lb,Lc;
InitList_Sq(La);
InitList_Sq(Lb);
InitList_Sq(Lc);
ElemType e1, e2, e3, e4, e5, e6,tempE;
e1.data = 1;
e2.data = 2;
e3.data = 3;
e4.data = 4;
e5.data = 5;
e6.data = 6;
tempE.data = 0;
ListInsert_Sq(La, 1, e1);
ListInsert_Sq(La, 2, e2);
ListInsert_Sq(La, 3, e3);
ListInsert_Sq(La, 4, e4);
ListInsert_Sq(La, 5, e5);
ListInsert_Sq(La,3, e6);
ShowList(La);
ListDelete_Sq(La, 5, tempE);
ShowList(La);
cout << "\n" << tempE.data<<"\n";
ListInsert_Sq(Lb, 1, e1);
ListInsert_Sq(Lb, 2, e2);
ListInsert_Sq(Lb, 3, e3);
ShowList(Lb);
ListInsert_Sq(Lb, 2, e2);
ListInsert_Sq(Lb, 3, e3);
ShowList(Lb);
MergeList_Sq(La, Lb, Lc);
ShowList(Lc);
system("pause");
return 0;
}
ShowList(Lc);
system("pause");
return 0;
}
Status InitList_Sq(SqList& L)
{
L.elem =(ElemType*) malloc(LIST_INIT_SIZE*sizeof(ElemType));
if (!L.elem)exit(OVERFLOW);
L.length = 0;
L.listSize = LIST_INIT_SIZE;
return OK;
}
{
L.elem =(ElemType*) malloc(LIST_INIT_SIZE*sizeof(ElemType));
if (!L.elem)exit(OVERFLOW);
L.length = 0;
L.listSize = LIST_INIT_SIZE;
return OK;
}
Status ListInsert_Sq(SqList& L, int i, ElemType e)
{
if (i<1 || i>L.length + 1)return ERROR;
ElemType* newbase = nullptr;
if (L.length >= L.listSize)
{
newbase = (ElemType*)realloc(L.elem, (L.listSize + LISTINCREAMENT)*sizeof(ElemType));
if (!newbase)exit(OVERFLOW);
L.elem = newbase;
L.listSize += LISTINCREAMENT;
}
ElemType* q = &L.elem[i - 1];
for (ElemType* p = &L.elem[L.length - 1];p >= q;p--)
{
*(p+1) = *p;
}
*q = e;
++L.length;
return OK;
}
{
if (i<1 || i>L.length + 1)return ERROR;
ElemType* newbase = nullptr;
if (L.length >= L.listSize)
{
newbase = (ElemType*)realloc(L.elem, (L.listSize + LISTINCREAMENT)*sizeof(ElemType));
if (!newbase)exit(OVERFLOW);
L.elem = newbase;
L.listSize += LISTINCREAMENT;
}
ElemType* q = &L.elem[i - 1];
for (ElemType* p = &L.elem[L.length - 1];p >= q;p--)
{
*(p+1) = *p;
}
*q = e;
++L.length;
return OK;
}
Status ListDelete_Sq(SqList& L, int i, ElemType& e)
{
if (i<1 || i>L.length + 1)return ERROR;
ElemType* p = &L.elem[i - 1];
e = *p;
for (ElemType* q = p;q < &L.elem[L.length - 1];q++)
{
*q = *(q + 1);
}
--L.length;
return OK;
}
{
if (i<1 || i>L.length + 1)return ERROR;
ElemType* p = &L.elem[i - 1];
e = *p;
for (ElemType* q = p;q < &L.elem[L.length - 1];q++)
{
*q = *(q + 1);
}
--L.length;
return OK;
}
Status MergeList_Sq(SqList& La, SqList& Lb, SqList& Lc)
{
Lc.length = La.length + Lb.length;
ElemType* newbase = nullptr;
if (Lc.length >= Lc.listSize)
{
newbase = (ElemType*)realloc(Lc.elem, LISTINCREAMENT*sizeof(ElemType));
if (!newbase)exit(OVERFLOW);
Lc.elem = newbase;
Lc.listSize += LISTINCREAMENT;
}
for (int i = 0;i < La.length;i++)
{
Lc.elem[i] = La.elem[i];
}
for (int j = 0;j < Lb.length;j++)
{
Lc.elem[La.length + j] = Lb.elem[j];
}
return OK;
}
{
Lc.length = La.length + Lb.length;
ElemType* newbase = nullptr;
if (Lc.length >= Lc.listSize)
{
newbase = (ElemType*)realloc(Lc.elem, LISTINCREAMENT*sizeof(ElemType));
if (!newbase)exit(OVERFLOW);
Lc.elem = newbase;
Lc.listSize += LISTINCREAMENT;
}
for (int i = 0;i < La.length;i++)
{
Lc.elem[i] = La.elem[i];
}
for (int j = 0;j < Lb.length;j++)
{
Lc.elem[La.length + j] = Lb.elem[j];
}
return OK;
}
Status ShowList(SqList& L)
{
cout << "\nJoker";
cout << "length:" << L.length<<"Data:";
for (int i = 0;i < L.length;i++)
{
cout << "--" << L.elem[i].data;
}
return OK;
}
{
cout << "\nJoker";
cout << "length:" << L.length<<"Data:";
for (int i = 0;i < L.length;i++)
{
cout << "--" << L.elem[i].data;
}
return OK;
}
0 0
- SqList
- SQList
- SQList
- Sqlist
- sqlist
- SQList
- SQList数据库
- ListInsert-SqList
- GetElem-SqList
- ListDelete-SqList
- SQList数据库
- JAVA连接SQList数据库
- 数据结构试验-Sqlist
- sqlist顺序表
- coredata VS sqlist
- SQList的操作
- sqlist数据库语法
- 顺序表《Sqlist》
- 最少知识原则
- zoj3869 Ace of Aces && zoj3880 Demacia of the Ancients(水)
- 在IIS上启用Gzip压缩(HTTP压缩)
- leetcode:Same Tree 【Java】
- Doxygen初学与简单应用
- Sqlist
- iis配置php环境
- HTTP协议详解(转)
- pat1018:锤子剪刀布
- hrbust 哈理工oj 2188 星际旅行【BFS+传送阵】
- LinkList
- 算法_11:线性优化_2: 整数规划
- 朱老师ARM裸机学习笔记(一):计算机基础知识
- markdown说明书