C Language: Header and header of "sequential table" static order table

Source: Internet
Author: User

#define  _CRT_SECURE_NO_WARNINGS 1#include<stdio.h> #include <stdlib.h> #include <assert.h > #include <string.h> #define  maxsize 1000typedef int datetype;typedef struct  seqlist{    datetype arr[maxsize];    size_t size;} seqlist;//Print static Order table Void printseqlist (SEQLIST&NBSP;*SEQ) {    assert (SEQ);     if  (seq->size == 0)     {         printf ("Static order table is currently empty!") \ n ");        return;    }     for  (int index = 0; index < seq->size; index++)      {        printf ("%d-> ",  Seq->arr[index]);     }}//Initialize Void init (seqlist *seq) {    assert (SEQ); &nbSp;   memset (seq->arr, 0, sizeof (datetype) * maxsize);     seq->size = 0;} Head plug Void pushhead (seqlist *seq, datetype x) {    assert (SEQ);     /*Seq->size = 0;*/    if  (seq->size >=  maxsize)     {        printf ("The static order table is currently full and cannot be inserted!") \ n ");        return;    }     seq->size++;    for  (int index = seq->size - 1;  index >= 0; index--)     {         Seq->arr[index + 1] = Seq->arr[index];    }     seq->arr[0] = x;} Head Delete void pophead (seqlist *seq) {&NBSP;&NBSP;&NBSP;&NBSP;IF&NBSP; (seq->size >= maxsize)     {         printf ("The static order table is currently full and cannot be inserted!") \ n ");        return;    }         for  (int index = 0; index < seq->size;  index++)     {        seq->arr[index] =  seq->arr[index + 1];    }    seq->size--;} Void test2 (SEQLIST&NBSP;*SEQ) {    init (seq);     pushback (seq,  0);     pushback (seq, 1);     pushback (Seq, 2);     pushback (seq, 3);     pushback (seq, 4);     Pushback (seq, 5);     printseqlist (SEQ);     printf ("\ n");  & NBsP;  pushhead (seq, 10);     printseqlist (SEQ);     printf ( "\ n");     pophead (seq);     printseqlist (seq);     printf ("\ n");} Int main () {    seqlist seq;    seq.size = 0;     test2 (&AMP;SEQ);      system ("pause");     return  0;}


This article is from the "C language 100-200 Prime" blog, please be sure to keep this source http://10740184.blog.51cto.com/10730184/1743136

C Language: Header and header of "sequential table" static order table

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.