本入門指南旨在幫助您用 Visual Studio 構建一個簡單的 C# 項目
為了方便起見
其他資源我們強烈推薦下面這些關於 C# 和
Archer
Deitel
Gunnerson
Platt
補遺
//
// QuickSort C#
// Copyright
//
// MSDN ACADEMIC ALLIANCE []
// This sample is part of a vast collection of resources we developed for
// faculty members in K
// The source code is provided
//
// Import namespaces
using System;
using System
using System
// Declare namespace
namespace MsdnAA
{
// Declare application class
class QuickSortApp
{
// Application initialization
static void Main (string[] szArgs)
{
// Print startup banner
Console
Console
Console
// Describe program function
Console
Console
// Prompt user for filenames
Console
string szSrcFile = Console
Console
string szDestFile = Console
// Read contents of source file
string szSrcLine;
ArrayList szContents = new ArrayList ();
FileStream fsInput = new FileStream (szSrcFile
StreamReader srInput = new StreamReader (fsInput);
while ((szSrcLine = srInput
{
// Append to array
szContents
}
srInput
fsInput
// Pass to QuickSort function
QuickSort (szContents
// Write sorted lines
FileStream fsOutput = new FileStream (szDestFile
StreamWriter srOutput = new StreamWriter (fsOutput);
for (int nIndex =
{
// Write line to output file
srOutput
}
srOutput
fsOutput
// Report program success
Console
}
// QuickSort implementation
private static void QuickSort (ArrayList szArray
{
// Check for non
if (nLower < nUpper)
{
// Split and sort partitions
int nSplit = Partition (szArray
QuickSort (szArray
QuickSort (szArray
}
}
// QuickSort partition implementation
private static int Partition (ArrayList szArray
{
// Pivot with first element
int nLeft = nLower +
string szPivot = (string) szArray[nLower];
int nRight = nUpper;
// Partition array elements
string szSwap;
while (nLeft <= nRight)
{
// Find item out of place
while (nLeft <= nRight && ((string) szArray[nLeft])
nLeft = nLeft +
while (nLeft <= nRight && ((string) szArray[nRight])
nRight = nRight
// Swap values if necessary
if (nLeft < nRight)
{
szSwap = (string) szArray[nLeft];
szArray[nLeft] = szArray[nRight];
szArray[nRight] = szSwap;
nLeft = nLeft +
nRight = nRight
}
}
// Move pivot element
szSwap = (string) szArray[nLower];
szArray[nLower] = szArray[nRight];
szArray[nRight] = szSwap;
return nRight;
}
}
}
補遺
使用應用程序啟動 Command Prompt(從
程序將提示您提供輸入和輸出文件的名稱
示例程序輸出下面是來自此 QuickSort C#
您可以查看下面的示例輸入文件
QuickSort C#
Copyright (c)
MSDN ACADEMIC ALLIANCE []
This example demonstrates the QuickSort algorithm by reading an input file
sorting its contents
Source: example
Output: output
The sorted lines have been written to the output file
查看示例輸入文件
Visual C#
Windows Embedded
JavaScript
Speech API
ASP
VBScript
Windows Media
Visual Basic
BizTalk Server
XML Parser
Internet Explorer
Visual C#
SQL Server
Windows XP
DirectX API
查看示例輸出文件
ASP
BizTalk Server
DirectX API
Internet Explorer
JavaScript
Speech API
SQL Server
VBScript
Visual Basic
Visual C#
Visual C#
Windows Embedded
Windows Media
Windows XP
XML Parser
From:http://tw.wingwit.com/Article/program/net/201311/13488.html