#define _crt_secure_no_warnings include include include, include include Seqlist.h "
void Initseqlist (Pseqlist pseq)
{
ASSERT (PSEQ);
pseq->size=0;
memset (pseq->arr,0,sizeof (Pseq->arr));
}
void pushback (pseqlist pseq,datatype data)
{
ASSERT (PSEQ);
if (pseq->size>=maxsize)
Return
pseq->arr[pseq->size++]=data;
}
void Pushfront (pseqlist pseq,datatype data)
{
int idx=0;
ASSERT (PSEQ);
if (pseq->size>=maxsize)
Return
for (IDX=PSEQ->SIZE-1;IDX>=0;–IDX)
{
pseq->arr[idx+1]=pseq->arr[idx];
}
pseq->arr[0]=data;
pseq->size++;
}
void Popback (Pseqlist pseq)
{
ASSERT (PSEQ);
if (pseq->size==0)
Return
pseq->size–;
}
void Popfront (Pseqlist pseq)
{
int idx=0;
ASSERT (PSEQ);
if (pseq->size==0)
return;
For (idx=0;idx< (pseq->size-1); ++idx)
{
pseq->arr[idx]=pseq->arr[idx+1];
}
pseq->size--;
}
void Printseq (Pseqlist pseq)
{
int idx=0;
ASSERT (PSEQ);
For (idx=0;idx< (pseq->size); ++idx)
{
printf ("%d", Pseq->arr[idx]);
}
printf ("\ n");
printf ("Common elements:%d\n", pseq->size);
}
void Insert (pseqlist pseq,size_t pos,datatype data)
{
int idx=0;
ASSERT (PSEQ);
if (pos>pseq->size)
Return
for (IDX=PSEQ->SIZE;IDX>POS;–IDX)
{
pseq->arr[idx]=pseq->arr[idx-1];
}
pseq->arr[pos]=data;
pseq->size++;
}
void Erase (Pseqlist pseq,size_t POS)
{
int idx=0;
ASSERT (PSEQ);
if (Pseq->size<=pos)
Return
for (IDX=POS;IDXSIZE-1;++IDX)
{
pseq->arr[idx]=pseq->arr[idx+1];
}
pseq->size–;
}
int Find (pseqlist pseq,datatype data)
{
int idx=0;
ASSERT (PSEQ);
for (IDX=0;IDXSIZE;++IDX)
{
if (Pseq->arr[idx]==data)
{
return idx;
}
}
}
void Remove (pseqlist pseq,datatype data)
{
int pos=0;
int idx=0;
ASSERT (PSEQ);
Pos=find (Pseq,data);
/*if ( -1!=pos)
{
Erase (Pseq,pos);
}*/
if (Pseq->size<=pos)
Return
for (IDX=POS;IDXSIZE-1;++IDX)
{
pseq->arr[idx]=pseq->arr[idx+1];
}
pseq->size–;
}
void RemoveAll (pseqlist pseq,datatype data)
{
int idx=0;
int count=0;
ASSERT (PSEQ);
for (IDX=0;IDX<PSEQ->SIZE;++IDX)
{
if (pseq->arr[idx]==data)
{
count++;
}
else
{
pseq->arr[idx-count]=pseq->arr[idx];
}
}
pseq->size-=count;
}
void Funtest ()
{
int ret = 0;
Seqlist seq;
Initseqlist (&SEQ);
Pushback (&seq,1);
Pushback (&seq,2);
Pushback (&seq,3);
Pushback (&seq,4);
Pushback (&seq,5);
Pushback (&seq,6);
Pushback (&seq,7);
Pushback (&seq,8);
Pushback (&seq,9);
Printseq (&SEQ);
Pushfront (&seq,10);
Pushfront (&seq,11);
Pushfront (&seq,12);
Printseq (&SEQ);
Popback (&SEQ);
Popback (&SEQ);
Popback (&SEQ);
Printseq (&SEQ);
Popfront (&SEQ);
Popfront (&SEQ);
Printseq (&SEQ);
Insert (&seq,3,29);
Insert (&seq,5,7);
Insert (&seq,6,16);
Printseq (&SEQ);
Ret=find (&seq,7);
printf ("%d\n", ret);
Erase (&seq,7);
Erase (&seq,4);
Printseq (&SEQ);
Ret=find (&seq,7);
printf ("%d\n", ret);
Pushback (&seq,7);
Pushback (&seq,8);
Pushback (&seq,9);
Printseq (&SEQ);
RemoveAll (&seq,7);
Printseq (&SEQ);
Remove (&seq,9);
Printseq (&SEQ);
}
int main ()
{
Funtest ();
System ("Pasue");
return 0;
} define MAXSIZE include