ShortWay in C# conversion from C++ to C#

A

Andreas Ott

Hello togehter,

I need urgent a conversion from C++ to C#.

The code in C++ is below.

Can someone help me here.

Thanks a lot.


Greet Andreas





// ShortWay.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <vector>
#include <limits>

#include <conio.h>

class Point
{
public:
int x;
int y;


Point(int x_pos, int y_pos):x(x_pos),y(y_pos){};
};


//inline int dist(Point a, Point b)
inline int dist(const Point & a, const Point & b)
{
// Maximums-Norm (L_oo)
return std::max(abs(a.x-b.x), abs(a.y-b.y));

}


int NN2(std::vector<Point> & PunktVektor)
{
int total_length = 0;
for (size_t k = 0; k < PunktVektor.size() - 1; ++k)
{
int min_dist = std::numeric_limits<int>::max();

// #### durchsuche von einem Ausgangspunkt die Gesamtliste
int index = -1;
for (size_t i = k + 1; i < PunktVektor.size(); ++i)
{
if ( dist(PunktVektor[k], PunktVektor) <= min_dist )
{
min_dist = dist(PunktVektor[k], PunktVektor);
index = i;
}
}

// #### tausche den Punkt in der Liste
std::swap(PunktVektor[k+1], PunktVektor[index]);
total_length += min_dist;
}
return total_length;
}



int main(int argc, _TCHAR* argv[])
{
//srand (time(NULL));
std::vector<Point> PunktVektor;
for (int i = 0; i<10; ++i)
{
PunktVektor.push_back(Point (rand() % 200, rand() % 200));
// 200x200-Gitter
printf("Zufaelliger Punkt: %d %d\n", PunktVektor.x,
PunktVektor.y);
}
printf("\nReihenfolge mit der Nearest-Neighbor-Heuristik:\n");



int length = NN2(PunktVektor);


for (size_t k = 0; k < PunktVektor.size(); ++k)
{

printf("%d %d\n", PunktVektor[k].x, PunktVektor[k].y);
}
printf("Gesamtlaenge: %d\n", length);

_getch();
}
 
D

David Anton

It will need adjustment, but it may help get you started:

using System;
public static class GlobalMembers
{
//inline int dist(Point a, Point b)
public static int dist(Point a, Point b)
{
// Maximums-Norm (L_oo)
return Math.Max(Math.Abs(a.x-b.x), Math.Abs(a.y-b.y));

}


public static int NN2(ref List<Point> PunktVektor)
{
int total_length = 0;
for (size_t k = 0; k < PunktVektor.Count - 1; ++k)
{
int min_dist = std.numeric_limits<int>.max();

// #### durchsuche von einem Ausgangspunkt die Gesamtliste
int index = -1;
for (size_t i = k + 1; i < PunktVektor.Count; ++i)
{
if (dist(PunktVektor[k], PunktVektor) <= min_dist)
{
min_dist = dist(PunktVektor[k], PunktVektor);
index = i;
}
}

// #### tausche den Punkt in der Liste
std.swap(PunktVektor[k+1], PunktVektor[index]);
total_length += min_dist;
}
return total_length;
}



internal static int Main(int argc, _TCHAR[] argv)
{
//srand (time(NULL));
List<Point> PunktVektor = new List<Point>();
for (int i = 0; i<10; ++i)
{
PunktVektor.Add(Point (RandomNumbers.NextNumber() % 200,
RandomNumbers.NextNumber() % 200));
// 200x200-Gitter
Console.Write("Zufaelliger Punkt: {0:D} {1:D}\n", PunktVektor.x,
PunktVektor.y);
}
Console.Write("\nReihenfolge mit der Nearest-Neighbor-Heuristik:\n");

int length = NN2(ref PunktVektor);

for (size_t k = 0; k < PunktVektor.Count; ++k)
{
Console.Write("{0:D} {1:D}\n", PunktVektor[k].x, PunktVektor[k].y);
}
Console.Write("Gesamtlaenge: {0:D}\n", length);

Console.ReadKey(true).KeyChar;
}
}
public class Point
{
public int x;
public int y;


public Point(int x_pos, int y_pos)
{
x = x_pos;
y = y_pos;
}
}
//----------------------------------------------------------------------------------------
// Copyright © 2006 - 2009 Tangible Software Solutions Inc.
// This class can be used by anyone provided that the copyright notice
remains intact.
//
// This class provides the ability to simulate the behavior of the C/C++
functions for
// generating random numbers, using the .NET Framework System.Random class.
// 'rand' converts to the parameterless overload of NextNumber
// 'random' converts to the single-parameter overload of NextNumber
// 'randomize' converts to the parameterless overload of Seed
// 'srand' converts to the single-parameter overload of Seed
//----------------------------------------------------------------------------------------
internal static class RandomNumbers
{
private static System.Random r;

internal static int NextNumber()
{
if (r == null)
Seed();

return r.Next();
}

internal static int NextNumber(int ceiling)
{
if (r == null)
Seed();

return r.Next(ceiling);
}

internal static void Seed()
{
r = new System.Random();
}

internal static void Seed(int seed)
{
r = new System.Random(seed);
}
}
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB


Andreas Ott said:
Hello togehter,

I need urgent a conversion from C++ to C#.

The code in C++ is below.

Can someone help me here.

Thanks a lot.


Greet Andreas





// ShortWay.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <vector>
#include <limits>

#include <conio.h>

class Point
{
public:
int x;
int y;


Point(int x_pos, int y_pos):x(x_pos),y(y_pos){};
};


//inline int dist(Point a, Point b)
inline int dist(const Point & a, const Point & b)
{
// Maximums-Norm (L_oo)
return std::max(abs(a.x-b.x), abs(a.y-b.y));

}


int NN2(std::vector<Point> & PunktVektor)
{
int total_length = 0;
for (size_t k = 0; k < PunktVektor.size() - 1; ++k)
{
int min_dist = std::numeric_limits<int>::max();

// #### durchsuche von einem Ausgangspunkt die Gesamtliste
int index = -1;
for (size_t i = k + 1; i < PunktVektor.size(); ++i)
{
if ( dist(PunktVektor[k], PunktVektor) <= min_dist )
{
min_dist = dist(PunktVektor[k], PunktVektor);
index = i;
}
}

// #### tausche den Punkt in der Liste
std::swap(PunktVektor[k+1], PunktVektor[index]);
total_length += min_dist;
}
return total_length;
}



int main(int argc, _TCHAR* argv[])
{
//srand (time(NULL));
std::vector<Point> PunktVektor;
for (int i = 0; i<10; ++i)
{
PunktVektor.push_back(Point (rand() % 200, rand() % 200));
// 200x200-Gitter
printf("Zufaelliger Punkt: %d %d\n", PunktVektor.x,
PunktVektor.y);
}
printf("\nReihenfolge mit der Nearest-Neighbor-Heuristik:\n");



int length = NN2(PunktVektor);


for (size_t k = 0; k < PunktVektor.size(); ++k)
{

printf("%d %d\n", PunktVektor[k].x, PunktVektor[k].y);
}
printf("Gesamtlaenge: %d\n", length);

_getch();
}
 
T

Tom Gonuts

Hello togehter,

I need urgent a conversion from C++ to C#.

The code in C++ is below.

Can someone help me here.

Thanks a lot.

Greet Andreas

// ShortWay.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <vector>
#include <limits>

#include <conio.h>

class Point
{
public:
int x;
int y;

Point(int x_pos, int y_pos):x(x_pos),y(y_pos){};

};

//inline int dist(Point a, Point b)
inline int dist(const Point & a, const Point & b)
{
// Maximums-Norm (L_oo)
return std::max(abs(a.x-b.x), abs(a.y-b.y));

}

int NN2(std::vector<Point> & PunktVektor)
{
int total_length = 0;
for (size_t k = 0; k < PunktVektor.size() - 1; ++k)
{
int min_dist = std::numeric_limits<int>::max();

// #### durchsuche von einem Ausgangspunkt die Gesamtliste
int index = -1;
for (size_t i = k + 1; i < PunktVektor.size(); ++i)
{
if ( dist(PunktVektor[k], PunktVektor) <= min_dist )
{
min_dist = dist(PunktVektor[k], PunktVektor);
index = i;
}
}

// #### tausche den Punkt in der Liste
std::swap(PunktVektor[k+1], PunktVektor[index]);
total_length += min_dist;
}
return total_length;

}

int main(int argc, _TCHAR* argv[])
{
//srand (time(NULL));
std::vector<Point> PunktVektor;
for (int i = 0; i<10; ++i)
{
PunktVektor.push_back(Point (rand() % 200, rand() % 200));
// 200x200-Gitter
printf("Zufaelliger Punkt: %d %d\n", PunktVektor.x,
PunktVektor.y);
}
printf("\nReihenfolge mit der Nearest-Neighbor-Heuristik:\n");

int length = NN2(PunktVektor);

for (size_t k = 0; k < PunktVektor.size(); ++k)
{

printf("%d %d\n", PunktVektor[k].x, PunktVektor[k].y);
}
printf("Gesamtlaenge: %d\n", length);

_getch();

}


Try this:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace ShortWay
{
public class Point
{
private int x;

public int X
{
get { return x; }
set { x = value; }
}
private int y;

public int Y
{
get { return y; }
set { y = value; }
}
/// <summary>
///
/// </summary>
/// <param name="xCoord"></param>
/// <param name="yCoord"></param>
public Point(int xCoord, int yCoord)
{
this.x = xCoord;
this.y = yCoord;
}
/// <summary>
///
/// </summary>
public Point()
: this(0, 0)
{
}

/// <summary>
///
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static int Distance(Point a, Point b)
{
return Math.Max(Math.Abs(a.x - b.x), Math.Abs(a.y - b.y));
}
/// <summary>
///
/// </summary>
/// <param name="PunkVector"></param>
/// <returns></returns>
public static int NN2(Collection<Point> PunkVector)
{
int totalLength = 0;
for (int i = 0; i < PunkVector.Count - 1; i++)
{
int min_dist = int.MaxValue;
int index = -1;
for (int j = i + 1; j < PunkVector.Count; j++)
{
int currentDistance = Point.Distance(PunkVector
, PunkVector[j]);
if (currentDistance <= min_dist)
{
min_dist = Point.Distance(PunkVector,
PunkVector[j]);
index = j;
}
}
Point tempPoint = PunkVector[i + 1];
PunkVector[i + 1] = PunkVector[index];
PunkVector[index] = tempPoint;
totalLength += min_dist;
}
return totalLength;
}
}
}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;

namespace ShortWay
{
class Program
{
static void Main(string[] args)
{
Collection<Point> PunkVector = new Collection<Point>();
Random rand = new Random(1000);
for (int i = 0; i < 10; i++)
{
int x = rand.Next() % 200;
int y = rand.Next() % 200;
Point p = new Point(x, y);
PunkVector.Add(p);
Console.WriteLine("x = {0} y = {1}", p.X, p.Y);
}

int length = Point.NN2(PunkVector);

for (int j = 0; j < PunkVector.Count; j++)
{
Console.WriteLine("x[{0}] = {1} y[{2}] = {3}", j,
PunkVector[j].X, j , PunkVector[j].Y);
}

Console.WriteLine("Length = {0}", length);
}
}
}

Tom
 
A

Andreas Ott

Hello together,
Hello Tom,

thanks, yes it is workling well.

//Console.ReadKey(true).KeyChar; // Is not ok, why?
Console.ReadKey(); // It is ok


I must convert still another algorithm. The last one, sure.
The ways in certain order must be driven off.
http://www1.minpic.de/bild_anzeigen.php?id=73772&key=30221506&ende
Can someone help me here also?

Thanks a lot.

Greet Andreas



// Sort_Wege.cpp :
//

#include "stdafx.h"
#include "Sort_Wege.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// Das einzige Anwendungsobjekt

CWinApp theApp;

using namespace std;

#pragma once
#include <vector>
#include <algorithm>

#include <conio.h>
#include <ctype.h>

#include <math.h>
static bool toogle;


// assumed relative Tolerance == absolute Tolerance, else
// if (Abs(x - y) <= Max(absTol, relTol * Max(Abs(x), Abs(y)))
inline bool isEqual( const double & x, const double & y,
const double& epsilon = 1e-12f )
{
return abs(x-y) < epsilon * max(1.0, max(abs(x), abs(y)));
}


vector<double> vorkommendeXWerte;
////static vector<bool> suchrichtung[vorkommendeXWerte.size()];
//bool suchrichtung[1000];
vector<bool> suchrichtung;

static bool GetSuchrichtung(double x)
{
int i=0;
for ( i=0; i<(int)vorkommendeXWerte.size(); ++i )
{
//if ( x == vorkommendeXWerte )
// break;

if ( fabs(x - vorkommendeXWerte) < 0.001 )
break;


/* if ( fabs(x,vorkommendeXWerte)<0.001 )
return suchrichtung; */
}
// ** i ist jetzt bekannt --> Suchrichtungsindex aus dem Vektor
Suchrichtung holen
bool richtung = suchrichtung;

return richtung;
// ... hier Fehlerbehandlung nicht vergessen
}



class CSortWay
{
public:
CSortWay(){}
CSortWay(double x, double y) { X = x; Y = y; }
~CSortWay(){}
typedef std::vector<CSortWay> data;

public:
double X;
double Y;

//static vector<double> vorkommendeXWerte;
////static vector<bool> suchrichtung[vorkommendeXWerte.size()];
//static vector<bool> suchrichtung[1000];


static bool SortCase1(const CSortWay var1,const CSortWay var2)
{
double x1 = var1.X;
double y1 = var1.Y;

double x2 = var2.X;
double y2 = var2.Y;


/*printf("~~~x1= %7.2f, y1=%7.2f x2= %7.2f, y2=%7.2f \r\n",
x1,
y1,
x2,
y2);*/

return( (x1<x2) || (x1==x2 && y1<y2) );

}

static bool SortCase2(const CSortWay var1,const CSortWay var2)
{
double x1 = var1.X;
double y1 = var1.Y;

double x2 = var2.X;
double y2 = var2.Y;

if ( x1<x2 || x1>x2 )
return false;
else if ( x1==x2 )
{
if ( GetSuchrichtung(x1) )
return y1<y2;
else
return y1>y2;
}
else
return false;
}


static bool SortCase3(const CSortWay var1,const CSortWay var2)
{
double x1 = var1.X;
double y1 = var1.Y;

double x2 = var2.X;
double y2 = var2.Y;

return( (y1<y2) || (y1==y2 && x1<x2) );

}

static bool SortCase4(const CSortWay var1,const CSortWay var2)
{
// ** TODO
double x1 = var1.X;
double y1 = var1.Y;

double x2 = var2.X;
double y2 = var2.Y;

return( (x1*x1 + y1*y1) < (x2*x2 + y2*y2) );
}
};







int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// MFC initialisieren und drucken. Bei Fehlschlag Fehlermeldung aufrufen.
if (!AfxWinInit:):GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: Den Fehlercode an Ihre Anforderungen anpassen.
_tprintf(_T("Schwerwiegender Fehler bei der MFC-Initialisierung\n"));
nRetCode = 1;
}
else
{
CSortWay::data mylistSortWay;

mylistSortWay.push_back(CSortWay(50,10));
mylistSortWay.push_back(CSortWay(50,20));
mylistSortWay.push_back(CSortWay(50,30));
mylistSortWay.push_back(CSortWay(50,40));

mylistSortWay.push_back(CSortWay(90,10));
mylistSortWay.push_back(CSortWay(90,20));
mylistSortWay.push_back(CSortWay(90,30));
mylistSortWay.push_back(CSortWay(90,40));

mylistSortWay.push_back(CSortWay(10,10));
mylistSortWay.push_back(CSortWay(10,20));
mylistSortWay.push_back(CSortWay(10,30));
mylistSortWay.push_back(CSortWay(10,40));

mylistSortWay.push_back(CSortWay(30,10));
mylistSortWay.push_back(CSortWay(30,20));
mylistSortWay.push_back(CSortWay(30,30));
mylistSortWay.push_back(CSortWay(30,40));

mylistSortWay.push_back(CSortWay(70,10));
mylistSortWay.push_back(CSortWay(70,20));
mylistSortWay.push_back(CSortWay(70,30));
mylistSortWay.push_back(CSortWay(70,40));


// ** Case 1
printf("Case 1\r\n");

std::sort(mylistSortWay.begin(),
mylistSortWay.end(),
CSortWay::SortCase1);
int count=0;
for ( CSortWay::data::iterator it2(mylistSortWay.begin());
it2!=mylistSortWay.end();
it2++ )
{
++count;
printf("Pos=%d x= %7.2f, y=%7.2f\r\n",
count,
(*it2).X,
(*it2).Y);
}
// ** Case 2
*********************************************************************
printf("Case 2\r\n");

// ** nach x sortieren!
std::sort(mylistSortWay.begin(),
mylistSortWay.end(),
CSortWay::SortCase1);

// ** jetzt die Spalten ermitteln
double merkeX = -9999;
vorkommendeXWerte.clear();
for ( CSortWay::data::iterator it2(mylistSortWay.begin());
it2!=mylistSortWay.end();
it2++ )
{
if ( merkeX != (*it2).X )
{
vorkommendeXWerte.push_back((*it2).X);
merkeX = (*it2).X;
}
}
// ** zu den Spalten die Richtungsumkehr ermitteln
bool toggle = false;
for(int i=0;i<(int)vorkommendeXWerte.size();++i)
{
suchrichtung.push_back(toggle);
toggle= !toggle;
}

std::sort(mylistSortWay.begin(),
mylistSortWay.end(),
CSortWay::SortCase2);

count=0;
for ( CSortWay::data::iterator it2(mylistSortWay.begin());
it2!=mylistSortWay.end();
it2++ )
{
++count;
printf("Pos=%d x= %7.2f, y=%7.2f\r\n",
count,
(*it2).X,
(*it2).Y);
}
// ** Case 3
printf("Case 3\r\n");

std::sort(mylistSortWay.begin(),
mylistSortWay.end(),
CSortWay::SortCase3);
count=0;
for ( CSortWay::data::iterator it2(mylistSortWay.begin());
it2!=mylistSortWay.end();
it2++ )
{
++count;
printf("Pos=%d x= %7.2f, y=%7.2f\r\n",
count,
(*it2).X,
(*it2).Y);
}
//// ** Case 4
// printf("Case 4\r\n");
//
// std::sort(mylistSortWay.begin(),
// mylistSortWay.end(),
// CSortWay::SortCase4);
// count=0;
// for ( CSortWay::data::iterator it2(mylistSortWay.begin());
// it2!=mylistSortWay.end();
// it2++ )
// {
// ++count;
// printf("Pos=%d x= %7.2f, y=%7.2f\r\n",
// count,
// (*it2).X,
// (*it2).Y);
// }
_getch();
}



return nRetCode;
}
 
A

Andreas Ott

Hello together,

perhaps, someone has a better algorithm.
I am grateful over ideas, example.

Thanks and have a nice weekend.

With best greets Andreas
thanks, yes it is workling well.

//Console.ReadKey(true).KeyChar; // Is not ok, why?
Console.ReadKey(); // It is ok


I must convert still another algorithm. The last one, sure.
The ways in certain order must be driven off.
http://www1.minpic.de/bild_anzeigen.php?id=73772&key=30221506&ende
Can someone help me here also?

Thanks a lot.

Greet Andreas



// Sort_Wege.cpp :
//

#include "stdafx.h"
#include "Sort_Wege.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// Das einzige Anwendungsobjekt

CWinApp theApp;

using namespace std;

#pragma once
#include <vector>
#include <algorithm>

#include <conio.h>
#include <ctype.h>

#include <math.h>
static bool toogle;


// assumed relative Tolerance == absolute Tolerance, else
// if (Abs(x - y) <= Max(absTol, relTol * Max(Abs(x), Abs(y)))
inline bool isEqual( const double & x, const double & y,
const double& epsilon = 1e-12f )
{
return abs(x-y) < epsilon * max(1.0, max(abs(x), abs(y)));
}


vector<double> vorkommendeXWerte;
////static vector<bool> suchrichtung[vorkommendeXWerte.size()];
//bool suchrichtung[1000];
vector<bool> suchrichtung;

static bool GetSuchrichtung(double x)
{
int i=0;
for ( i=0; i<(int)vorkommendeXWerte.size(); ++i )
{
//if ( x == vorkommendeXWerte )
// break;

if ( fabs(x - vorkommendeXWerte) < 0.001 )
break;


/* if ( fabs(x,vorkommendeXWerte)<0.001 )
return suchrichtung; */
}
// ** i ist jetzt bekannt --> Suchrichtungsindex aus dem Vektor
Suchrichtung holen
bool richtung = suchrichtung;

return richtung;
// ... hier Fehlerbehandlung nicht vergessen
}



class CSortWay
{
public:
CSortWay(){}
CSortWay(double x, double y) { X = x; Y = y; }
~CSortWay(){}
typedef std::vector<CSortWay> data;

public:
double X;
double Y;

//static vector<double> vorkommendeXWerte;
////static vector<bool> suchrichtung[vorkommendeXWerte.size()];
//static vector<bool> suchrichtung[1000];


static bool SortCase1(const CSortWay var1,const CSortWay var2)
{
double x1 = var1.X;
double y1 = var1.Y;

double x2 = var2.X;
double y2 = var2.Y;


/*printf("~~~x1= %7.2f, y1=%7.2f x2= %7.2f, y2=%7.2f \r\n",
x1,
y1,
x2,
y2);*/

return( (x1<x2) || (x1==x2 && y1<y2) );

}

static bool SortCase2(const CSortWay var1,const CSortWay var2)
{
double x1 = var1.X;
double y1 = var1.Y;

double x2 = var2.X;
double y2 = var2.Y;

if ( x1<x2 || x1>x2 )
return false;
else if ( x1==x2 )
{
if ( GetSuchrichtung(x1) )
return y1<y2;
else
return y1>y2;
}
else
return false;
}


static bool SortCase3(const CSortWay var1,const CSortWay var2)
{
double x1 = var1.X;
double y1 = var1.Y;

double x2 = var2.X;
double y2 = var2.Y;

return( (y1<y2) || (y1==y2 && x1<x2) );

}

static bool SortCase4(const CSortWay var1,const CSortWay var2)
{
// ** TODO
double x1 = var1.X;
double y1 = var1.Y;

double x2 = var2.X;
double y2 = var2.Y;

return( (x1*x1 + y1*y1) < (x2*x2 + y2*y2) );
}
};







int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// MFC initialisieren und drucken. Bei Fehlschlag Fehlermeldung
aufrufen.
if (!AfxWinInit:):GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: Den Fehlercode an Ihre Anforderungen anpassen.
_tprintf(_T("Schwerwiegender Fehler bei der
MFC-Initialisierung\n"));
nRetCode = 1;
}
else
{
CSortWay::data mylistSortWay;

mylistSortWay.push_back(CSortWay(50,10));
mylistSortWay.push_back(CSortWay(50,20));
mylistSortWay.push_back(CSortWay(50,30));
mylistSortWay.push_back(CSortWay(50,40));

mylistSortWay.push_back(CSortWay(90,10));
mylistSortWay.push_back(CSortWay(90,20));
mylistSortWay.push_back(CSortWay(90,30));
mylistSortWay.push_back(CSortWay(90,40));

mylistSortWay.push_back(CSortWay(10,10));
mylistSortWay.push_back(CSortWay(10,20));
mylistSortWay.push_back(CSortWay(10,30));
mylistSortWay.push_back(CSortWay(10,40));

mylistSortWay.push_back(CSortWay(30,10));
mylistSortWay.push_back(CSortWay(30,20));
mylistSortWay.push_back(CSortWay(30,30));
mylistSortWay.push_back(CSortWay(30,40));

mylistSortWay.push_back(CSortWay(70,10));
mylistSortWay.push_back(CSortWay(70,20));
mylistSortWay.push_back(CSortWay(70,30));
mylistSortWay.push_back(CSortWay(70,40));


// ** Case 1
printf("Case 1\r\n");

std::sort(mylistSortWay.begin(),
mylistSortWay.end(),
CSortWay::SortCase1);
int count=0;
for ( CSortWay::data::iterator it2(mylistSortWay.begin());
it2!=mylistSortWay.end();
it2++ )
{
++count;
printf("Pos=%d x= %7.2f, y=%7.2f\r\n",
count,
(*it2).X,
(*it2).Y);
}
// ** Case 2
*********************************************************************
printf("Case 2\r\n");

// ** nach x sortieren!
std::sort(mylistSortWay.begin(),
mylistSortWay.end(),
CSortWay::SortCase1);

// ** jetzt die Spalten ermitteln
double merkeX = -9999;
vorkommendeXWerte.clear();
for ( CSortWay::data::iterator it2(mylistSortWay.begin());
it2!=mylistSortWay.end();
it2++ )
{
if ( merkeX != (*it2).X )
{
vorkommendeXWerte.push_back((*it2).X);
merkeX = (*it2).X;
}
}
// ** zu den Spalten die Richtungsumkehr ermitteln
bool toggle = false;
for(int i=0;i<(int)vorkommendeXWerte.size();++i)
{
suchrichtung.push_back(toggle);
toggle= !toggle;
}

std::sort(mylistSortWay.begin(),
mylistSortWay.end(),
CSortWay::SortCase2);

count=0;
for ( CSortWay::data::iterator it2(mylistSortWay.begin());
it2!=mylistSortWay.end();
it2++ )
{
++count;
printf("Pos=%d x= %7.2f, y=%7.2f\r\n",
count,
(*it2).X,
(*it2).Y);
}
// ** Case 3
printf("Case 3\r\n");

std::sort(mylistSortWay.begin(),
mylistSortWay.end(),
CSortWay::SortCase3);
count=0;
for ( CSortWay::data::iterator it2(mylistSortWay.begin());
it2!=mylistSortWay.end();
it2++ )
{
++count;
printf("Pos=%d x= %7.2f, y=%7.2f\r\n",
count,
(*it2).X,
(*it2).Y);
}
//// ** Case 4
// printf("Case 4\r\n");
//
// std::sort(mylistSortWay.begin(),
// mylistSortWay.end(),
// CSortWay::SortCase4);
// count=0;
// for ( CSortWay::data::iterator it2(mylistSortWay.begin());
// it2!=mylistSortWay.end();
// it2++ )
// {
// ++count;
// printf("Pos=%d x= %7.2f, y=%7.2f\r\n",
// count,
// (*it2).X,
// (*it2).Y);
// }
_getch();
}



return nRetCode;
}
 
A

Andreas Ott

Hello,

maybe a easy question.
What do you mean with this?

Console.ReadKey(true).KeyChar;

Error 1 Only assignment, call, increment, decrement, and new object
expressions can be used as a statement
C:\Sort_Wege\ShortWay_CSharp2\Program.cs 145 13 ShortWay_CSharp2

Why not so --> Console.ReadKey();

Greet Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top