Home > Back-end >  C array class problem great god for help
C array class problem great god for help

Time:09-25

CodePudding user response:

This is to write a similar to the realization of the linear table data structure?

CodePudding user response:

Search the dichotomy

CodePudding user response:

reference 1/f, chicken dishes to flying reply:
this is to write a similar to the realization of the linear table data structure?

No, by class to implement the program function is ok, just began to learn, thin, can't write, bosses give directions!

CodePudding user response:

# include
using namespace std;

Typedef struct
{
Double * array;//data pointer
Int capacity;//array maximum capacity
Int size;//the number of elements in the array now
} Array;
//create an empty array
Array * CreateArray (int capacity)
{
Array * a=new Array;
A - & gt; Capacity=capacity;
A - & gt; Size=0;
A - & gt; Array=(double *) malloc (capacity * sizeof (double));
return a;
}
//the output array capacity
Int print_capacity (Array * a)
{
Return a - & gt; Capacity;
}
//the output array elements actual quantity
Int print_size (Array * a)
{
Return a - & gt; The size;
}
//insert element at any position (array is 0 subscript 1)
Void insert (Array * a, int position, double x)
{
If (a - & gt; Size==a - & gt; Capacity) return;//is full
- the position;
If (position<0 | | position & gt;=a - & gt; Capacity) return;
//the above if whether insert position legal
For (int I=position + 1; i<=a - & gt; The size; + + I)
A - & gt; Array [I]=a - & gt; Array [I - 1);
A - & gt; Array [position]=x;
+ + a - & gt; The size;
}
//delete any position of the element
Void does (Array * a, int position)
{
If (a - & gt; Size==0) return;//an empty array
- the position;
If (position<0 | | position & gt;=a - & gt; The size) return;
//the above if whether delete location legal
For (int I=position; iA - & gt; Array [I]=a - & gt; Array [I + 1);
- a - & gt; The size;
}
//to empty array
Void clearArray (Array * a)
{
A - & gt; Size=0;
}

Int main (void)
{
.
}

CodePudding user response:

Take a look at this line not line, I useless class to write, but you should be able to understand and then write it on your own
  • Related