-
A heap is a sequence of elements organized like a binary tree. Each heap element corresponds to a tree node. First value order [first.
Finally) is in the root directory, and the predicate is sorted by order. For example, if the predicate is larger, each element in the heap satisfies the following; And each element is greater than or equal to the parent. The smallest element is stored at the root, and all children are saved with progressively larger values.
The make heap function converts [the last one of the ranges first] to a heap.
The sort heap function is created using the make heap function for sorting"heapified.
The push heap function inserts a new value in the heap.
The pop heap function is swapped by [first, last], specifies the first and last elements in the heap, and then reduces the length of the previous sequence of restored heap properties.
For example, numbers
After that, call make heap
numbers
After that, call sort heap
numbers
After that, push heap() is called
numbers
After that, pop heap is called
numbers
-
Do you make the problem clearer? I don't know what you mean? make heap,push heap's source code?
-
You save the subscripts of the array to a temporary array, and at the same time as sorting the original array, you also perform the same swap on the temporary array, and when the target array is sorted, your subscript array will naturally be arranged. If you need **+20 points, I'll write it to you, this is the easiest way.
-
I'm late, and the rain falls deep in the mountains is a simple and easy way to use.
-
The rain falling deep into the mountains is very useful.
-
It depends on the number of numbers and array elements you have.
If the number is not too large and the array does not have many elements, you can use the shift calculation.
If the array elements are large or have many elements, use a two-dimensional array or structure.
The first line of a two-dimensional array is the original array, and the second line is the ordinal number.
For example, an array of a[2][n], where a[0] is the number of the original array a[1].
I want it when I exchange.
int ntemp;
for (int i=0;ia[0][j])
After the arrangement, you can output a[1], and the above sorting is just to explain that you can also switch to a faster method.
The structure is the same, with two elements, one is a numeric value and the other is a number.
The principle is very simple, basically the same as the above, so I won't say much about it)
However, in C++, if the int of a 32-bit machine is 4 bytes, most numbers will not exceed the size, so you may need this.
Your array is int na[n]; An array with no more than 256 elements, and the numerical size of the elements is no more than 2 23
or no more than 65,536 elements, with values between -32767 and 32768.
For the sake of convenience, I only said that there are no more than 256 elements, and the numerical size of the element is not greater than 2 23 in one case, and the latter is the same as this one, you can just change it (0=-2 23 can be like this).
Note: This method does not support random output with duplicate numbers, that is, if you have two identical numbers, the first one will always come first.
for(int i=0;ina[j])
Then there's the output, which you can do (only the last 8 bits).
for(int i=0;icout<<(na[i]&0xff)
-
Chain stack output two loops in reverse order is fine.
#ifndef stack_h_
#define stack_h_
const int null=0;
enum error_code ;
template
struct node
template
node::node()
template
node::node(t item,node*add_on)template
class stack
template
stack::stack()
template
stack::~stack()
template
stack::stack(stack &item)else
topnode=newtop;
template
error_code stack::push(t item)template
error_code stack::pop()template
template
bool stack::empty()
#endif
-
for(i = 7;i >= 0;i--) without any additional definition of variables.
You can also define a j according to your ideas
int j;
for(i = 7,j = 8;i >= 0;i--)for(i = j; i >=0; i --b[i] = a[i];
-
Obviously, you can directly fill in num, why do you want to toss this?。。。
-
Modified as above!
The while loop is a bit problematic, and after new, you need to delete, and main needs to return. That's basically all ...
namespace c__ces
class program >>>More
int a =;
int b =; >>>More
2D array address - > row address - > column address (variable address) - > variable value, or excerpt a description for you. >>>More
#include
using namespace std; >>>More