Two-way linked list to handle:
Two-way linked list, although sequential comparison, many times. But inserting does not move the data. Do not know the two who prevail. or code to run it.
The code is as follows:
#include <math.h>
#include <algorithm>
using namespace Std;
struct souttwo{int value, Next, pre;}; void Sortlinktwo (int data[], int m, int n, souttwo out[])//bidirectional chain {out[0].pre= out[0].next= 0; for (int head= 0, count= 0, end= 0, i= 0; i<= m; i++) if (i== m)//Knot Bundle {if (head> 0) {souttwo t= out[0]; out[0]= Out[head], out[head]= t; Chain head to 0 out[out[0].next].pre= out[out[0].pre].next= 0; Out[out[head].next].pre= out[out[head].pre].next= Head; }} else if (count== n && data[i]>= out[out[head].pre].value)//Invalid data continue; else for (int see= head, j= 0;; see= Out[see].next, J + +) {if (j== count) Append {if (out[count].value= data[i], count> 0) {out[out[head].pre].next= Count Out[count].pre= Out[head].pre; Out[count].next= Head; Out[head].pre= count; } count++; Break } else if (data[i]< out[see].value)//Insert {end= count== n? Out[head].pre:count; if (count== n && see!= end)//delete End section out[out[end].next].pre= out[end].pre, Ou T[out[end].pre].next= Out[end].next; if (out[end].value= data[i], count< n | | see!= end) {out[out[see].pre].next= end; Out[end].pre= Out[see].pre; out[end].next= See; Out[see].pre= end; if (see== head) head= Out[see].pre; count+= count< N; } break; }}}//----------------------void control (int n) {int m= n< 9? n+ 2:n* Pow (10, 3); Double tms= GetTickCount (); int *data= New Int[m], *datasort= new int[m]; for (int i= 0; i< m; i++)//random number datasort[i]= data[i]= random (m); ShowTime ("Manufacturing withMachine Count ", TMS); Sort (Datasort, datasort+ m); ShowTime ("Standard sequencing Time", TMS); souttwo*out= new souttwo[n+ 1]; Sortlinktwo (Data, M, N, out); ShowTime ("Bidirectional Chain processing Time", TMS); for (int see= 0, i= 0; i<= N; see= out[see].next, i++) if (i== n | | datasort[i]!= out[see].value) {showmessage (i== n?) "Find good": "Error"} delete []datasort; delete []data; delete []out;}
100 million take 100,000, spents: 339.49 seconds. Worse than binary, but close. Added a lot of space. No good. Think about, the maintenance chain of the forward and subsequent, all to increase the assignment. So think that a single strand is better? Next time, use a single strand.
How to filter out the top 100,000 minimum values in a large number of data (e.g. 100 million)? The third