найти ближайшее местоположение из исходной точки

Предположим, у нас есть следующая проблема - мы хотим прочитать набор (x, y) координат и имя, затем отсортировать их по порядку, увеличив расстояние от начала координат (0 0). Вот алгоритм, который использует простейшую пузырьковую сортировку:

 #include<iostream>
    #include <algorithm>
    using namespace std;
    struct point{
        float x;
        float y;
         char name[20];

         };
      float dist(point p){
          return p.x*p.x+p.y*p.y;
            }
       void sorting(point pt[],int n){
          bool doMore = true;
        while (doMore) {
            doMore = false;  // Assume no more passes unless exchange made.
            for (int i=0; i<n-1; i++) {
                if (dist(pt[i]) > dist(pt[i+1])) {
                    // Exchange elements
                    point temp = pt[i]; pt[i] = pt[i+1]; pt[i+1] = temp;
                    doMore = true;  // Exchange requires another pass.
                }
            }
        }

       }
       void display(point pt[],int n){
            for (int i=0;i<n;i++){
                cout<<pt[i].name<< " ";
                   }
       }
    int main(){
    point pts[1000];
    int n=0;

    while (cin>>pts[n].name>>pts[n].x>>pts[n].y){
        n++;

    }
     sorting(pts,n);
     display(pts,n);

    return 0;
    }

Но я хочу написать алгоритм сортировки STL вместо пузырьковой сортировки. Как это сделать?

Я имею в виду, {// свойства } Public Facility: Entity {общедоступное виртуальное местоположение Location {get; набор; } } ...

У меня есть две таблицы, Locations и Facilities

Они отображаются на два класса,

public Location : Entity
{
   //properties
}

public Facility : Entity
{
    public virtual Location Location { get; set; }
}

Все работает просто великолепно, пока я не изменю средства на это

public Facility : Location
{

}

Теперь я получаю исключение из nHibernate, говоря

NHibernate.ADOException was unhandled by user code
  Message=could not execute query
 InnerException: System.Data.SqlClient.SqlException
       Message=Invalid object name 'Facility'.

По какой-то причине он не создает множественное имя таблицы в строку sql.

Спасибо за любую помощь!

РЕДАКТИРОВАТЬ

Это мое текущее TableNameConvention

public class TableNameConvention : IClassConvention
{
    public void Apply(FluentNHibernate.Conventions.Instances.IClassInstance instance)
    {
        instance.Table(Inflector.Net.Inflector.Pluralize(instance.EntityType.Name));
    }
}

Когда Facility наследует от Entity, Фонд работает через этот метод. Когда он наследует от Location, он не

Edit 2 Думал, я бы все опубликовал ... Database diagram

public class AutoPersistenceModelGenerator : IAutoPersistenceModelGenerator
{

    #region IAutoPersistenceModelGenerator Members

    public AutoPersistenceModel Generate()
    {
        var mappings = new AutoPersistenceModel();
        mappings.AddEntityAssembly(typeof(Person).Assembly).Where(GetAutoMappingFilter);
        mappings.Conventions.Setup(GetConventions());
        mappings.Setup(GetSetup());
        mappings.IgnoreBase<Entity>();
        mappings.IgnoreBase(typeof(EntityWithTypedId<>));
        mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();

        return mappings;

    }

    #endregion

    private Action<AutoMappingExpressions> GetSetup()
    {
        return c =>
        {
            c.FindIdentity = type => type.Name == "Id";
        };
    }

    private Action<IConventionFinder> GetConventions()
    {
        return c =>
        {
            c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ForeignKeyConvention>();
            c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.HasManyConvention>();
            c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.HasManyToManyConvention>();
            c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ManyToManyTableNameConvention>();
            c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.PrimaryKeyConvention>();
            c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.ReferenceConvention>();
            c.Add<BHP.DEC.Data.NHibernateMaps.Conventions.TableNameConvention>();
        };
    }

    /// <summary>
    /// Provides a filter for only including types which inherit from the IEntityWithTypedId interface.
    /// </summary>

    private bool GetAutoMappingFilter(Type t)
    {
        return t.GetInterfaces().Any(x =>
                                        x.IsGenericType &&
                                        x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>));
    }
}
5
задан Jason More 26 August 2010 в 22:29
поделиться