# include <stdio.h>
# include<string.h>
# include<memory.h>
# include<assert.h>
# define MAX_SIZE 100
typedef int DATATYPE;
typedef struct SEQLIST
{
DataType Arry[max_size];
size_t size;
}seqlist;//defining a struct order table
void Initseqlist (Seqlist * pseq)
{
memset (pseq->arry,0,sizeof (DataType) *max_size);//Initialization Order table
pseq->size=0;
}
void Pushback (seqlist *pseq,datatype x)
{
ASSERT (PSEQ);
if (pseq->size>=max_size)
{
printf ("The Seqliist is Full");//Assign values to sequential tables
return;
}
pseq->arry[pseq->size++]=x;
}
void Popback (Seqlist *pseq)
{
ASSERT (PSEQ);
pseq->size--;//removed from the end
}
void Erase (Seqlist *s,size_t POS)
{
ASSERT (s);
if (pos>=s->size)
{
printf ("Over the Max data!");
Return
}
while (pos++< (s->size-1))
{
s->arry[pos]=s->arry[pos+1];//Delete the value at the specified position
}
}
void Remove (seqlist *s,datatype x)
{
ASSERT (s);
DataType i,j;//Delete the first X
for (i=0;i<s->size;i++)
{
if (X==s->arry[i])
{
Break
}
}
if ((i==s->size-1) && (s->arry[i]!=x))
{
printf ("X not found in the Order table");
}
Else
{
for (j=i;j<s->size;j++)
{
s->arry[i]=s->arry[i+1];
}
}
s->size--;
}
void RemoveAll (Seqlist*s,datatype x)
{
int i,j,count=0;
ASSERT (s);//Delete all X
for (i=0;i<s->size;i++)
{
if (X==s->arry[i])
{
for (j=i;j<s->size;j++)
{
s->arry[i]=s->arry[i+1];
}
count++;
}
Else
{
if ((i==s->size-1) && (s->arry[i]!=x) && (count==0))
{
printf ("X not found in the Order table");
}
}
}
s->size=s->size-count;
}
void Sort (seqlist *s)
{ assert (s);
int i,j,temp;//Bubble Sort
for (i=0;i<s->size;i++)
{
for (j=s->size-1;j >=i;j--)
{
if (s->arry[j]<s->arry [J-1])
{
temp=s->arry[j];
s->arry[j]=s->arry[j-1];
s->arry[j-1]=temp;
}
}
}
}
Void output (Seqlist *s)
{
assert (s);
int i=0;
for (i=0;i<s->size;i++)
{
printf ("%d", S->arry[i]);
}
}
int main ()
{
Seqlist L;
Initseqlist (&L);
Pushback (&l,3);
Pushback (&l,7);
Pushback (&l,1);
Pushback (&l,12);
Pushback (&l,3);
Pushback (&l,3);
Pushback (&l,2);
Pushback (&l,1);
Popback (&L);
Erase (&l,1);
Remove (&l,12);
RemoveAll (&l,3);
Sort (&L);
Output (&l);
return (0);
}
This article from the "It Technology Notes" blog, declined reprint!
How to create a sequential table and some actions on the superscript