The construction of the sequential table is a structure of itself, the use of an array, the size of the open memory space is fixed. No chain-like structure of the open space of the controllability. The most basic data structure cognition.
Then let's look at the basic implementations and ideas in the data structure:
#include "SeqList.h" #include <stdio.h> initialization of the #include <assert.h>//sequential table void Initseqlist (SEQLIST*&NBSP;SEQ) {int _index = 0;assert (seq); for (; _index < max_size;+ +_index) {seq->_array[_index] = 0;} seq->_size = 0;} Print Order table Void printseqlist (SEQLIST*&NBSP;SEQ) {int _index = 0;assert (seq); if (0 == Seq->_size) {printf ("The order table has no data \ n"); return;} for (; _index<seq->_size;++_index) {printf ("%d ", Seq->_array[_index]);} printf ("\ n");} Trailing insert Void pushback (seqlist* seq, datatype x) {int _checkseq;assert (seq); if (1 == (_checkseq = checkseqlist (seq)) {printf ("Order table full"); return;} Seq->_array[seq->_size++] = x;} Trailing delete void popback (SEQLIST*&NBSP;SEQ) {int _checkseq;assert (seq); if (0 == (_checkseq = checkseqlist (seq)) {printf ("The order table is empty \ n"); return;} seq->_array[--seq->_size] = 0;} Head Insertion Void pushfront (seqlist* seq, datatype x) {int _index = 0;int _checkseq;assert (seq); if (1 == (_checkseq = checkseqlist (seq)) {printf ("Order table full"); return;} for (; _index < seq->_size;++_index) {seq->_array[seq->_size-_index] = seq->_ ARRAY[SEQ->_SIZE&NBSP;-&NBSP;_INDEX&NBSP;-&NBSP;1];} seq->_array[0] = x;seq->_size++;} Head Delete Void popfront (seqlist* seq) {int _index = 0;int _checkseq;assert (seq); if (0 == (_checkseq = checkseqlist (seq))) {printf ("The order table is empty \ n"); return;} for (; _index<seq->_size-1;++_index) {seq->_array[_index] = seq->_array[_index+1];} seq->_size--;} Insert Operation Void insert (seqlist* seq, size_t pos, datatype x) {int _index = seq->_size;int _checkseq;assert (seq); if (1 == (_checkseq = checkseqlist (seq)) {printf ("The Order table is full"); return;} if (pos < 0 | | pos > seq->_size) {printf ("Modify position out of bounds"); return;} for (; _index > pos;--_index) {seq->_array[_index] = seq->_array[_index - 1];} seq->_array[pos] = x;seq->_size++;} Find. Return-1 indicates no data found Int find (seqlist* seq, datatype x) {int _endindex = 0; ASSERT (seq); for (; _endindex < seq->_size;++ _endindex) {if (x == seq->_ Array[_endindex]) {return _endindex;}} Return -1;} Erase input coordinates data void erase (seqlist* seq, size_t pos) {Int _index = pos;assert (seq ); if (pos < 0 | | pos > seq->_size) {printf ("Modify position out of bounds"); return;} for (; _index < seq->_size-1;++_index) {seq->_array[_index] = seq->_array[_index+ 1];}} Removes the first found function Void remove (seqlist* seq, datatype x) {int _pos = 0;int _ Index = -1;for (; _pos < seq->_size;++_pos) {if(X == seq->_array[_pos]) {_index = _pos;break;}} if ( -1 != _index) {for (; _index < seq->_size - 1;++_index) {seq->_array[_ INDEX]&NBSP;=&NBSP;SEQ->_ARRAY[_INDEX&NBSP;+&NBSP;1];} seq->_size--;} else{printf ("No this Number");}} Remove all queries to the data, the algorithm is more high-quality. Move the replacement directly. Void removeall (seqlist* seq, datatype x) {int _pos = 0;int _index = 0;for (; _pos < seq->_size;++_pos) {if (X != seq->_array[_pos]) {Seq->_array [_index] = seq->_array[_pos];_index++;}}} Modify the function. Void modify (seqlist* seq, size_t pos, datatype x) {assert (SEQ); if (pos < 0 | | pos > seq->_size) {printf ("Modify position out of bounds"); return;} seq->_array[pos] = x; }int checkseqlist (SEQLIST&NBSP;*SEQ) {if (MAX_SIZE == seq- >_size) {return 1;} if (0 == seq->_size) {return 0;}}
That's all. is actually the basic thinking of some simple data structure. The basic thinking of adding and removing changes and inserting.
This article is from the "egg-left" blog, please be sure to keep this source http://memory73.blog.51cto.com/10530560/1703683
"C Language" sequential table, array