How to create a sequential table and some actions on the superscript

Source: Internet
Author: User

# 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.