#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
typedef int elemtype;
typedef struct SQlist
{
elemtype data[10];
int length;
int capacity;
}SQlist,*PSQlist;
void Init_SQlist(PSQlist ps);
bool Insert(PSQlist ps, int pos, int val);
bool Del_pos(PSQlist ps, int pos);
bool Del_pos(PSQlist ps, int val);
bool IsEmpty(PSQlist ps);
bool IsFull(PSQlist ps);
int Get_Length(PSQlist ps);
void Clear(PSQlist ps);
void Destory(PSQlist ps);
void expland(PSQlist ps, int n);
#include<stdio.h>
#include<assert.h>
#include"sqlist.h"
void Init_SQlist(PSQlist ps)
{
assert(ps!= NULL);
ps->length = 0;
}
bool Insert(PSQlist ps, int pos, int val)
{
assert(ps != NULL&&pos<=0&&pos>=ps->length);
if(ps==NULL||pos<0||pos>ps->length)
{
return false;
}
if (IsFull(ps))
{
return false;
}
for (int i = ps->length - 1; i >= pos; i--)
{
ps->data[i+1] = ps->data[i];
}
ps->data[pos] = val;
ps->length++;
return true;
}
bool Del_pos(PSQlist ps, int pos)
{
assert(ps != NULL&&pos>=0&&pos<ps->length);
if (IsEmpty(ps))
{
return false;
}
for (int i = pos + 1; i < ps->length; i++)
{
ps->data[i - 1] = ps->data[i];
}
ps->length--;
return true;
}
bool Del_val(PSQlist ps, int val)
{
assert(ps != NULL);
if (IsEmpty(ps))
{
return false;
}
int tmp = -1;
for (int i = 0; i < ps->length; i++)
{
if (ps->data[i] == val)
{
tmp = i;
break;
}
}
if (tmp == -1)
{
return false;
}
Del_pos(ps, tmp);
return true;
}
bool IsEmpty(PSQlist ps)
{
assert(ps != NULL);
return ps->length == 0;
}
bool IsFull(PSQlist ps)
{
assert(ps != NULL);
return ps->length == 10;
}
int Get_Length(PSQlist ps)
{
return ps->length;
}
void Clear(PSQlist ps)
{
ps->length = 0;
}
void Destory(PSQlist ps)
{
Clear(ps);
}
void Show(PSQlist ps)
{
for (int i = 0; i < ps->length; i++)
{
printf("%d ", ps->data[i]);
}
printf("\n");
}
void expland(PSQlist ps, int n)
{
assert(ps != NULL);
if (ps->length == ps->capacity)
{
ps->capacity *= n;
elemtype* newdata = (elemtype*)malloc(sizeof(elemtype) * ps->capacity);
for (int i = 0; i < ps->length; i++)
{
newdata[i]= ps->data[i];
}
}
}
#include<stdio.h>
#include"sqlist.h"
int main()
{
SQlist sq;
Init_SQlist(&sq);
return 0;
}