#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 (&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