日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
QuickSort C# .NET剖析

本文向大家介紹QuickSort C# .NET,可能好多人還不知道QuickSort C# .NET,沒有關系,看完本文你肯定有不少收獲,希望本文能教會你更多東西。

創(chuàng)新互聯(lián)建站是一家專業(yè)提供麥蓋提企業(yè)網(wǎng)站建設,專注與成都做網(wǎng)站、成都網(wǎng)站制作、H5網(wǎng)站設計、小程序制作等業(yè)務。10年已為麥蓋提眾多企業(yè)、政府機構等服務。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進行中。

本文旨在幫助您用 Visual Studio 構建一個簡單的 C# 項目。它無法進行全面的介紹。我們鼓勵您查詢關于 C# 和 .NET 的其他資源,以便更多地學習這些技術。在完成本教程之后,您至少有了一個可用的項目,在您研究 Visual C# 時,可以從修改此這些代碼開始。

下面是 QuickSort C# .NET 示例應用程序的完整源代碼。您可以復制、使用和分發(fā)這些代碼(無版權費)。注意,這些源代碼以"原樣"提供并且不作任何保證。

 
 
 
  1. //QuickSort C# .NET Sample Application  
  2. //Copyright 2001-2002 Microsoft Corporation. All rights reserved.  
  3. //  
  4. //MSDN ACADEMIC ALLIANCE [http://www.msdn.microsoft.com/academic]  
  5. //This sample is part of a vast collection of resources we developed for  
  6. //faculty members in K-12 and higher education. Visit the MSDN AA web site for more!  
  7. //The source code is provided "as is" without warranty.  
  8. //  
  9. // Import namespaces  
  10. using System;  
  11. using System.Collections;  
  12. using System.IO;  
  13. // Declare namespace  
  14. namespace MsdnAA  
  15. {  
  16. // Declare application class  
  17. class QuickSortApp  
  18. {  
  19. // Application initialization  
  20. static void Main (string[] szArgs)  
  21. {  
  22. // Print startup banner  
  23. Console.WriteLine ("\nQuickSort C#.NET Sample Application");  
  24. Console.WriteLine ("Copyright (c)2001-2002 Microsoft Corporation. All rights reserved.\n");  
  25. Console.WriteLine ("MSDN ACADEMIC ALLIANCE [http://www.msdnaa.net/]\n");  
  26. // Describe program function  
  27. Console.WriteLine ("This example demonstrates the QuickSort algorithm by reading an input file,");  
  28. Console.WriteLine ("sorting its contents, and writing them to a new file.\n");  
  29. // Prompt user for filenames  
  30. Console.Write ("Source: ");  
  31. string szSrcFile = Console.ReadLine ();  
  32. Console.Write ("Output: ");  
  33. string szDestFile = Console.ReadLine ();  
  34. // Read contents of source file  
  35. string szSrcLine;  
  36. ArrayList szContents = new ArrayList ();  
  37. FileStream fsInput = new FileStream (szSrcFile, FileMode.Open, FileAccess.Read);  
  38. StreamReader srInput = new StreamReader (fsInput);  
  39. while ((szSrcLine = srInput.ReadLine ()) != null)  
  40. {  
  41. // Append to array  
  42. szContents.Add (szSrcLine);  
  43. }  
  44. srInput.Close ();  
  45. fsInput.Close ();  
  46. // Pass to QuickSort function  
  47. QuickSort (szContents, 0, szContents.Count - 1);  
  48. // Write sorted lines  
  49. FileStream fsOutput = new FileStream (szDestFile, FileMode.Create, FileAccess.Write);  
  50. StreamWriter srOutput = new StreamWriter (fsOutput);  
  51. for (int nIndex = 0; nIndex < szContents.Count; nIndex++)  
  52. {  
  53. // Write line to output file  
  54. srOutput.WriteLine (szContents[nIndex]);  
  55. }  
  56. srOutput.Close ();  
  57. fsOutput.Close ();  
  58. // Report program success  
  59. Console.WriteLine ("\nThe sorted lines have been written to the output file.\n\n");  
  60. }  
  61. // QuickSort implementation  
  62. private static void QuickSort (ArrayList szArray, int nLower, int nUpper)  
  63. {  
  64. // Check for non-base case  
  65. if (nLower < nUpper)  
  66. {  
  67. // Split and sort partitions  
  68. int nSplit = Partition (szArray, nLower, nUpper);  
  69. QuickSort (szArray, nLower, nSplit - 1);  
  70. QuickSort (szArray, nSplit + 1, nUpper);  
  71. }  
  72. }  
  73. // QuickSort partition implementation  
  74. private static int Partition (ArrayList szArray, int nLower, int nUpper)  
  75. {  
  76. // Pivot with first element  
  77. int nLeft = nLower + 1;  
  78. string szPivot = (string) szArray[nLower];  
  79. int nRight = nUpper;  
  80. // Partition array elements  
  81. string szSwap;  
  82. while (nLeft <= nRight)  
  83. {  
  84. // Find item out of place  
  85. while (nLeft <= nRight && ((string) szArray[nLeft]).CompareTo (szPivot) <= 0)  
  86. nLeftnLeft = nLeft + 1;  
  87. while (nLeft <= nRight && ((string) szArray[nRight]).CompareTo (szPivot) > 0)  
  88. nRightnRight = nRight - 1;  
  89. // Swap values if necessary  
  90. if (nLeft < nRight)  
  91. {  
  92. szSwap = (string) szArray[nLeft];  
  93. szArray[nLeft] = szArray[nRight];  
  94. szArray[nRight] = szSwap;  
  95. nLeftnLeft = nLeft + 1;  
  96. nRightnRight = nRight - 1;  
  97. }  
  98. }  
  99. // Move pivot element  
  100. szSwap = (string) szArray[nLower];  
  101. szArray[nLower] = szArray[nRight];  
  102. szArray[nRight] = szSwap;  
  103. return nRight;  
  104. }  
  105. }  

關于 QuickSort C# .NET為了演示 QuickSort Visual C# .NET 示例應用程序實際是如何運行的,我們提供了編譯好的可執(zhí)行文件。您可以通過編譯這些項目文件來創(chuàng)建自己的可執(zhí)行文件。單擊 Quicksort_Visual_CSharp_.NET.exe,下載源代碼項目文件和可執(zhí)行文件包。

使用應用程序啟動 Command Prompt(從"開始"菜單運行"cmd.exe")。使用 CD 命令將目錄更改為可執(zhí)行文件所在的目錄。然后運行"quicksort.exe".

程序將提示您提供輸入和輸出文件的名稱。任何包含多行的文本文件均可使用。如果需要,可以使用記事本來創(chuàng)建一個此類文件。然后,該程序將對輸入文件的內(nèi)容進行排序,并且將其寫入輸出文件。

示例程序輸出下面是來自此 QuickSort C# .NET 應用程序的一個實例的輸出。此示例演示了 QuickSort 算法,方法是讀取輸入文件、對文件的內(nèi)容進行排序,然后將其寫入新的文件。

【編輯推薦】

  1. C# 3.0編譯器簡單介紹
  2. C#使用函數(shù)重載學習筆記
  3. Visual C#對數(shù)據(jù)庫處理概述
  4. C#具有隱式類型聲明描述
  5. C#使用SharpZipLib分析

分享題目:QuickSort C# .NET剖析
本文地址:http://m.5511xx.com/article/ccccjjj.html