Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 03:06

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Radix Sort C#

Discussion on Radix Sort C# within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: May 2009
Posts: 127
Received Thanks: 21
Radix Sort C#

Hallo Community,

ich habe ein kleines Problem.

Ich habe schon das meistse des Quelltextes kommentiert, allerdings verstehe ich den in #ten gekennzeichneten Bereich nicht....

Ich wäre euch sehr dankbar, wenn Ihr mir beim verstehen dieser 4 Zeilen behilflich sein könntet!

Code:
/* Written by Sanchit Karve (born2c0de)
   Contact Me at born2c0de AT dreamincode DOT net
*/
 
#include <stdio.h>
 
#define MAX 20
//#define SHOWPASS
 
void print(int *a,int n) // Funktion Printf nur für Array
{
                int i;      // Laufvariable   
                // a[i] = der Anzahl der eingegebenen Arrays    
        for(i=0;i<n;i++)    
                        printf("%d\t",a[i]);
}
   
void radixsort(int *a,int n)
{
                int i,b[MAX],m=0,exp=1;
                for(i=0;i<n;i++)// n = Elementanzahl
                {
                        if(a[i]>m) // wenn a[element (i) ] größer als m ( = 0) dann
                                m=a[i]; // setzte = sogroß wie das elemnt 
                        
                }// SUCHE DES GROESSTEN ARRAY ELEMNTS!!!
               
                while(m/exp>0)// solange m ( = größtes element) / 1 ist größer als 0
                {
                        int bucket[10]={0}; // erstellt array mit 10 Feldern und alle beinhalten die Zahl 0
                        for(i=0;i<n;i++) // solange i ( = 0) ist kleiner als n( = elementanzahl)       
                                bucket[a[i]/exp%10]++; 
                                // a[i]/exp%10 macht die letzte Ziffer ausfindig
                                // bucket[a[i]/exp%10]++; Erhöht die Arraystelle der Aufindig gemachten Endzahl um1 ( letzte zahl 9 array an Stelle 9 und eins erhöht)
                                
##########################################################################################################################################
                        for(i=1;i<10;i++) // solange i ( = 1) ist keliner als 10
                                //printf("\nFeld%d",bucket[i]);
                                bucket[i]+=bucket[i-1];
                                // bucket[i] = Anzahl der Zahlen in jedem Array Part ist 
                                // bucket[i-1] = Anzahl der Zahlen im Array vor dem jetzigen Array
                        for(i=n-1;i>=0;i--)// i = n (Anzalh der elemente -1) solange bis i größer oder gleich 0 ist
                                b[--bucket[a[i]/exp%10]]=a[i]; <------
##########################################################################################################################################
                        for(i=0;i<n;i++)
                                a[i]=b[i];
                        exp*=10;
 
//#ifdef SHOWPASS
                    printf("\nPASS   : ");
                        print(a,n);
//#endif
                }               
        }
 
 
int main()
{
           int arr[MAX]; // Array Größe
           int i,n; // n = Elemntzahl, i = Laufvariable für for-schleife
           
           printf("Enter total elements (n < %d) : ",MAX);
           scanf("%d",&n);// Einlesen der Anzahl
           
           printf("Enter %d Elements : ",n);
           for(i=0;i<n;i++) // einlesen der einzelnen Elemnte
                                scanf("%d",&arr[i]);  //speichern der einzelnen Elemnte in dem Array
           
           
           printf("\nARRAY  : ");
           print(&arr[0],n);// Augsgeben aller Array veriablen
           
           
           radixsort(&arr[0],n);
           
           printf("\nSORTED : ");
           print(&arr[0],n);
           printf("\n");
           
           getchar();
           getchar();
           getchar();
           
           return 0;
}

Vielen Dank im Vorraus!

Liebe Grüße
Scarface

Hat sich gerklärt =)

Bitte schließen!
*scarface* is offline  
Reply


Similar Threads Similar Threads
In-Game Sort bug
06/26/2011 - Rappelz - 1 Replies
Hey, Is there any fixes on the in-game sort bugs?
[Help]Some sort of Tool...
02/28/2010 - EO PServer Hosting - 2 Replies
Hey there, Is there any kind of tool that lets someone ban/change name and other stuff? same as http://www.elitepvpers.com/forum/eo-pserver-hosting /228552-release-acme-admin-tool.html but something else.. because it wouldn't let others use commands.. it would say no table found.. Thanks :awesome:
some sort of fishing bot?
08/28/2009 - Rohan - 5 Replies
hey i was just wondering i f i could request some sort of bot for fishing? so the arrow hits the center every time? it pisses me off lol i keep missing it :P thx in advance if anyone wants to do it
Some new sort of bug?
10/28/2008 - Dekaron Private Server - 3 Replies
hey i think there is some new sort of bug or something in the 360x server few days ago i tried to open new char at the third server and after i did it dced me and gave me some error when im trying to log in the error is 600,300 today my guild mate in JackAss told me it happend to one of our players and i think more of our players got it cause there are no ppl online atm and yesterday we had 10+ active members so i hope someone got the solution for this crap
Sort of New
03/11/2008 - Say Hello - 1 Replies
hi, i never posted here yet and so that thing will go away on my screen, i post here now... okie dokie.



All times are GMT +1. The time now is 03:08.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.