Home > Back-end >  C data structure to solve
C data structure to solve

Time:09-16

Class practice - defined in a sequential storage structure of the linear list class, used to store a sorting of integers:
# define INIT_LISTSIZE 100
The class IntList
{
Private:
Int * Base;//base address
Int Length;//the effective length of the linear table (the actual number of elements)
Int ListSize;//the size of the linear table (at most) storage element
Public:
IntList (int n);//constructor, n is the number of element
~ IntList () {} what will we do////to do
Void ShowList ();//output linear table
Int length () {return length; }//return the effective length of the linear table
Value (unsigned int item) {return base (item 1), }//return the first item element
Void InsertNum (int num);//insert element in the existing linear table num
};
//the realization of the constructor
IntList: : IntList (int n)
{Base=new int [INIT_LISTSIZE];//the application memory
ListSize=INIT_LISTSIZE;
Length=n;
If (n<=0)
{//how to deal with? }
Cout<& lt;" Type "& lt; //the following press insertion sort input and store integers
Cin> The Base [0].
for(int i=1; i{
.
}
}
//ShowList () function is the implementation of the
//InsertNum () function is the implementation of the
Void main ()
{//test code, itself}
  • Related