Monday 15 April 2013

arrays - C# program problems[Sorting two massives into one] -



arrays - C# program problems[Sorting two massives into one] -

i need sort 2 arrays one,but 0000000 happens in middle of output. whats problem? cant find mistake, in bubble sort? here code

'consoleapplication5.vshost.exe' (clr v4.0.30319: consoleapplication5.vshost.exe): loaded 'c:\windows\microsoft.net\assembly\gac_msil\system.data.datasetextensions\v4.0_4.0.0.0__b77a5c561934e089\system.data.datasetextensions.dll'. skipped loading symbols. module optimized , debugger alternative 'just code' enabled. 'consoleapplication5.vshost.exe' (clr v4.0.30319: consoleapplication5.vshost.exe): loaded 'c:\windows\microsoft.net\assembly\gac_msil\microsoft.csharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\microsoft.csharp.dll'. skipped loading symbols. module optimized , debugger alternative 'just code' enabled. 'consoleapplication5.vshost.exe' (clr v4.0.30319: consoleapplication5.vshost.exe): loaded 'c:\windows\microsoft.net\assembly\gac_32\system.data\v4.0_4.0.0.0__b77a5c561934e089\system.data.dll'. skipped loading symbols. module optimized , debugger alternative 'just code' enabled. 'consoleapplication5.vshost.exe' (clr v4.0.30319: consoleapplication5.vshost.exe): loaded 'c:\windows\microsoft.net\assembly\gac_msil\system.xml\v4.0_4.0.0.0__b77a5c561934e089\system.xml.dll'. skipped loading symbols. module optimized , debugger alternative 'just code' enabled. 'consoleapplication5.vshost.exe' (clr v4.0.30319: consoleapplication5.vshost.exe): loaded 'c:\windows\microsoft.net\assembly\gac_msil\mscorlib.resources\v4.0_4.0.0.0_ru_b77a5c561934e089\mscorlib.resources.dll'. module built without symbols. thread 0x1264 has exited code 259 (0x103). thread 0xc4c has exited code 259 (0x103). thread 0xdc4 has exited code 0 (0x0). thread 0x16f4 has exited code 259 (0x103). 'consoleapplication5.vshost.exe' (clr v4.0.30319: consoleapplication5.vshost.exe): loaded 'c:\users\vas\documents\visual studio 2013\projects\consoleapplication5\consoleapplication5\bin\debug\consoleapplication5.exe'. symbols loaded. programme '[1112] consoleapplication5.vshost.exe: programme trace' has exited code 0 (0x0). programme '[1112] consoleapplication5.vshost.exe' has exited code -1073741510 (0xc000013a).

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; namespace consoleapplication2 { class programme { static void main(string[] args) { int[] array1 = new int[20]; int[] array2 = new int[20]; int[] array = new int[40]; int k = 0; random rnd = new random(); console.writeline("Исходный массив №1:"); (int = 0; < 20; i++) { array1[i] = rnd.next(-100, +100); console.write("{0} ", array1[i]); } console.writeline(); console.writeline("Исходный массив №2:"); (int = 0; < 20; i++) { array2[i] = rnd.next(-100, +100); console.write("{0} ", array2[i]); } console.writeline(); (; k < 20; k++) { array[k] = array1[k]; } (; k > 20; k++) { array[k] = array2[k - 20]; } console.writeline("Отсортированный массив:"); bubblesort(ref array); (int = 0; < 40; i++) { console.write("{0} ", array[i]); } console.readkey(); } static void bubblesort(ref int[] a) { (int = 0; < a.length; i++) { (int j = + 1; j < a.length; j++) { if (a[j] < a[i]) { var temp = a[i]; a[i] = a[j]; a[j] = temp; } } } } } }

this should be:

(int k = 0; k < 20; k++) { array[k] = array1[k]; } (int k = 0; k < 20; k++) { array[k + 20] = array2[k]; }

you

(int k = 0; k < 20; k++) { array[k] = array1[k]; array[k + 20] = array2[k]; }

but due memory pipeline caching, 2 loops faster.

c# arrays sorting

No comments:

Post a Comment