/ Published in: C#
                    
                                        Sort a file that contains integers between 1 and thousand. The output file should contain the entries like (n-times 1, followed by n-times 2 and so on): 1111222333555... But - you are not allowed to load all entries into memory at once. How to solve it? Here is my solution.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace testhash { class Program { static void Main(string[] args) { { for (int i = 1; i < 1000000; i++) { tw.Write(r.Next(1, 1000)); tw.Write(Environment.NewLine); } } { string line; while((line = reader.ReadLine()) != null) { table[Convert.ToInt32(line)] += 1; } //int sum = table.Sum(); //Console.WriteLine(sum); { for(var i = 0; i <= table.Count()-1;i++) { for(int writeTimes = 1; writeTimes <= table[i];writeTimes++) { tw.Write(i); tw.Write(Environment.NewLine); } } } } } } }
Comments
                    Subscribe to comments
                
                