Announcement

Collapse
No announcement yet.

SelectionSort Problem beim Zugriff auf Array

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • SelectionSort Problem beim Zugriff auf Array

    Hallo,

    ich möchte gerne auf ein Array zugreifen, um es dann per SelectionSort zu sortieren.
    Leider schaffe ich es nicht ans Array zu kommen. Mit einem Array direkt in der Klasse habe ich es hinbekomme.
    Hier mein Quellcode

    Behaelter.cs
    Code:
    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    
     
    namespace Uebung7  
    {  
      public class Behaelter  
      {  
          private Kunde[] container = new Kunde[20];  
    
     
        public Kunde[] Create()  
        {  
          container[0] = new Kunde(7);  
          container[1] = new Kunde(19);  
          container[2] = new Kunde(20);  
          container[3] = new Kunde(3);  
          container[4] = new Kunde(6);  
          container[5] = new Kunde(12);  
          container[6] = new Kunde(1);  
          container[7] = new Kunde(9);  
          container[8] = new Kunde(16);  
          container[9] = new Kunde(8);  
          container[10] = new Kunde(18);  
          container[11] = new Kunde(15);  
          container[12] = new Kunde(11);  
          container[13] = new Kunde(5);  
          container[14] = new Kunde(17);  
          container[15] = new Kunde(13);  
          container[16] = new Kunde(2);  
          container[17] = new Kunde(14);  
          container[18] = new Kunde(10);  
          container[19] = new Kunde(4);  
    
     
          return container;  
        }  
      }  
    }
    Kunde.cs
    Code:
    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    
     
    namespace Uebung7  
    {  
      public class Kunde  
      {  
    
     
        public Kunde(int prio)  
        {  
          Priority = prio;  
        }  
    
     
        private int m_Priority;  
        public int Priority  
        {  
          get  
          {  
            return m_Priority;  
          }  
          set  
          {  
            m_Priority = value;  
          }  
    
     
            }  
                
      }  
    }
    Programm.cs
    Code:
    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    
     
    namespace Uebung7  
    {  
        public class Sorter  
        {  
            public static void SelectionSort(char[] array)  
            {  
                int marker = array.Length - 1;  
                while (marker >= 0)  
                {  
                    // bestimme Position des größten Elementes  
                    int max = maxPos(array, 0, marker);  
                    // Vertausche Werte von array[marker] mit array[max]  
                    swap(array, marker, max);  
                    marker--;  
                }  
            }  
            private static void swap(char[] array, int idx1, int idx2)  
            {  
                char tmp = array[idx1];  
                array[idx1] = array[idx2];  
                array[idx2] = tmp;  
            }  
            private static int maxPos(char[] array, int lo, int hi)  
            {  
                int max = hi;  
                for (int i = lo; i < hi; i++)  
                    if (array[i] > array[max]) max = i;  
                return max;  
            }  
        }  
    
     
        public class test  
        {  
           public static void Main(String[] args)  
            {  
             //   char[] SortierFeld = { 'S', 'O', 'R', 'T', 'I', 'E', 'R', 'B', 'E', 'I', 'S', 'P', 'I', 'E', 'L' };  
               //  System.Console.WriteLine(SortierFeld);  
               // Sorter.SelectionSort(SortierFeld);  
               // System.Console.WriteLine(SortierFeld);  
     
           ***HIER SOLL DER ZUGRIFF ANSTATT SORTIERFELD mit dem Kundenarray passieren***  
    
     
            }  
        }  
    }
    Mit dem SortiertFeld hat alles geklappt.
    Danke vorab!
Working...
X