Russian Sorting Halves Danilin

Status
Not open for further replies.

DANILIN

Active member
Joined
Oct 19, 2018
Messages
44
Programming Experience
10+
Russian Sorting Halves and fast and human
sorts 1'000'000 in 2.2 seconds on QB64
sorts 1'000'000 in 0.3 seconds on PureBasic

me interested implementation of algorithm in language C#

number of elements is written to file with c:/N.txt or use variable n
array d(n) can be read from a file or synthesized in a program

C#:
' Russian Sorting Halves Danilin
 
DECLARE SUB RussianSortingHalvesDAV (ab!, yz!, part!, age!)
CLOSE
OPEN "c:/N.txt" FOR INPUT AS #1
INPUT #1, n
'n=1234567
age = 1 + LOG(n) / LOG(2)
PRINT n
 
DIM SHARED d(n) 'AS LONG
DIM SHARED a(n) 'AS LONG
 
'OPEN "c:/ISX.txt" FOR INPUT AS #2
'FOR i=1 TO n: INPUT #2, d(i): NEXT
 
'FOR i = 1 TO n: d(i) = n - i + 1: NEXT ' INT(RND*n)
FOR i = 1 TO n: d(i) = INT(RND * n): NEXT '
 
FOR k = 1 TO 20: PRINT d(k);: NEXT: PRINT: PRINT
FOR k = n - 19 TO n: PRINT d(k);: NEXT: PRINT: PRINT
 
start = TIMER
 
IF age > 0 THEN
    CALL RussianSortingHalvesDAV(1, n, 1, age)
END IF
 
finish = TIMER
 
PRINT finish - start; "second ": PRINT
 
OPEN "c:/=RuSortHalves_dav.txt" FOR OUTPUT AS #3
PRINT #3, finish - start; "second "
PRINT #3, n; "elements", "RECURSION"
FOR i = 1 TO 22: PRINT #3, d(i): NEXT
FOR i = n - 22 TO n: PRINT #3, d(i): NEXT
 
FOR k = 1 TO 20: PRINT d(k);: NEXT: PRINT: PRINT
FOR k = n - 19 TO n: PRINT d(k);: NEXT: PRINT: PRINT
 
END
 
SUB RussianSortingHalvesDAV (ab, yz, part, age)
 
IF yz - ab < 1 THEN EXIT SUB
 
FOR i = ab TO yz
    summa = summa + d(i)
NEXT
middle = summa / (yz - ab + 1)
 
abc = ab - 1
xyz = yz + 1
 
FOR i = ab TO yz
    IF d(i) < middle THEN abc = abc + 1: a(abc) = d(i): ELSE xyz = xyz - 1: a(xyz) = d(i)
NEXT
 
FOR i = ab TO yz: d(i) = a(i): NEXT
 
IF part < age THEN
    IF abc >= ab THEN CALL RussianSortingHalvesDAV(ab, abc, part + 1, age)
    IF xyz <= yz THEN CALL RussianSortingHalvesDAV(xyz, yz, part + 1, age)
END IF
 
END SUB

Russian Sorting Halves Danilin visualisation
https://www.youtube.com/watch?v=UxvSwOtpiuc
https://www.youtube.com/watch?v=9poxfAcbxFQ

rusortpol10.gif


me interested implementation of algorithm in language C#
 
Data transfer between programs
specifically 1 sign: number of nodes

grafline.gif


C#:
//GRAF11.cs
using System; 
using System.IO;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
namespace GRAF11
{
    public class Program
{
static void Main()
    {
Application.Run(new GRAF11());
    }
    }
    class GRAF11 : Form 
    {
int[] x = new int[10];
int[] y = new int[10];
Random rand = new Random();
ComboBox comboBoxD;
Button buttonA;

    public GRAF11()
    {
comboBoxD = new ComboBox();
    comboBoxD.Location = new Point(45, 50);
    comboBoxD.Width = 50;
    comboBoxD.Items.Add("7");
    comboBoxD.Items.Add("5");
    comboBoxD.Items.Add("3");
    comboBoxD.SelectedIndex = 1;
buttonA = new Button();    
    buttonA.Location = new System.Drawing.Point(30, 80);
    buttonA.Text = "START";
    buttonA.Click+=buttonA_Click;
var labelV = new Label();
    labelV.Text = "CIRCLES";
    labelV.Location = new System.Drawing.Point(45, 28);
Controls.Add(comboBoxD);
Controls.Add(buttonA);
Controls.Add(labelV);
    }
private void buttonA_Click(object sender, EventArgs e)
    {
for (int i = 1; i <10; i++)
        {
x[i]=150+rand.Next(100);
y[i]=20+rand.Next(100);
        }
var outFile = new StreamWriter("dan.txt");
outFile.WriteLine(comboBoxD.Text);
for (int i = 1; i <10; i++)
        {
outFile.WriteLine(x[i]);
outFile.WriteLine(y[i]);
        }
outFile.Close();

    Process.Start("GRAF22.exe");
        }
    }
}

C#:
//GRAF22.cs
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
namespace GRAF22
{
    public class Program
{
static void Main()
    {
Application.Run(new GRAF22());
    }
}
    class GRAF22 : Form
    {
int[] x = new int[10];
int[] y = new int[10];
int[] z = new int[2];

    public GRAF22()
    {
var inpFile = new StreamReader("dan.txt");

z[1] = Convert.ToInt32(inpFile.ReadLine());

for (int i = 1; i <10; i++)
        {
x[i] = Convert.ToInt32(inpFile.ReadLine());
y[i] = Convert.ToInt32(inpFile.ReadLine());
        }
inpFile.Close();
}

protected override void OnPaint(PaintEventArgs dav)
    {
Graphics da = dav.Graphics;
Pen pen = new Pen(ForeColor);
for (int i = 1; i <= z[1]; i++)
da.DrawEllipse(new Pen(Color.Magenta, i), x[i]-5, y[i]-5, 10, 10);

for (int i = 1; i <= z[1]-1; i++)
for (int j = i+1; j <= z[1]; j++)
    {
da.DrawLine(new Pen(Color.Red, i), new Point(x[i], y[i]), new Point(x[j], y[j]));
System.Threading.Thread.Sleep(150);
    }
        }
    }
}
 
Last edited:
c# version of "guess my number game" 1 line
C#:
using System; using System.Text;namespace GURU { class Program { static void Main(string[] args) { Random rand = new Random(); int Russia = 0; int n = 0; int num = 0; dav: if(Russia == 0) {Russia = 2222; num = rand.Next(100)+1; goto dav; }else if (Russia != 0) {Console.Write("? "); n = Convert.ToInt32(Console.ReadLine());} if (n < num) { Console.WriteLine("MORE"); goto dav;}else if (n > num) { Console.WriteLine("less"); goto dav;}else if (n == num) {Console.Write("da"); Console.ReadKey(); }else goto dav;}}}// DANILIN Russia 9-9-2019 guessnum.cs
using System; using System.Text;namespace GURU { class Program { static void Main(string[] args) { Random rand = new Random(); int Russia = 0; int n = 0; int num = 0; dav: if(Russia == 0) {Russia = 2222; num = rand.Next(100)+1; goto dav; }else if (Russia != 0) {Console.Write("? "); n = Convert.ToInt32(Console.ReadLine());} if (n < num) { Console.WriteLine("MORE"); goto dav;}else if (n > num) { Console.WriteLine("less"); goto dav;}else if (n == num) {Console.Write("da"); Console.ReadKey(); }else goto dav;}}}// DANILIN Russia 9-9-2019 guessnum.cs

c# version of "guess my number game" 1 line

qbasic version of "guess my number game" 1 line
C#:
1 IF Russia = 0 THEN Russia = 2222: RANDOMIZE TIMER: num = INT(RND * 100) + 1: GOTO 1 ELSE IF Russia <> 0 THEN INPUT n: IF n < num THEN PRINT "MORE": GOTO 1 ELSE IF n > num THEN PRINT "less": GOTO 1 ELSE IF n = num THEN PRINT "da": END ELSE GOTO 1 'DANILIN Russia 9-9-2019 guessnum.bas
1 IF Russia = 0 THEN Russia = 2222: RANDOMIZE TIMER: num = INT(RND * 100) + 1: GOTO 1 ELSE IF Russia <> 0 THEN INPUT n: IF n < num THEN PRINT "MORE": GOTO 1 ELSE IF n > num THEN PRINT "less": GOTO 1 ELSE IF n = num THEN PRINT "da": END ELSE GOTO 1 'DANILIN Russia 9-9-2019 guessnum.bas

qbasic version of "guess my number game" 1 line
 
Your thread is not updated periodically and should be closed, as it is kinda random. I would like a moderator to review this thread for relativity, as your posts are very sporadic.
 
Sheepings is correct. Using a single thread to post every code example you have that you think might help someone is not a correct use of this forum. If you have information that you want to share, create a thread with a title that describes the topic and select "Tip" as the prefix. If you have more information on a different topic, create a new thread for that topic.
 
Status
Not open for further replies.
Back
Top Bottom