C#數(shù)組反轉(zhuǎn)與排序?qū)嵗治?/h1>
更新時(shí)間:2015年01月26日 15:35:54 投稿:shichen2014
這篇文章主要介紹了C#數(shù)組反轉(zhuǎn)與排序,實(shí)例分析了數(shù)組反轉(zhuǎn)與常見的排序技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
本文實(shí)例分析了C#數(shù)組反轉(zhuǎn)與排序的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
C#數(shù)組反轉(zhuǎn)
復(fù)制代碼 代碼如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 數(shù)據(jù)反轉(zhuǎn)
{
class Program
{
static void Main(string[] args)
{
string[] strAllay = { ""};
string s;
for (int i = 0; i < strAllay.Length / 2; i++)//strAllay.Length/2是因?yàn)榻?jīng)過(將數(shù)組的長度值除以2)次就可以將數(shù)組成員進(jìn)行反轉(zhuǎn)了
{
s = strAllay[i];
strAllay[i] = strAllay[strAllay.Length - 1 - i];//如果i等于數(shù)組第一項(xiàng)值()的時(shí)候,將它與最后一個(gè)值()互換。
strAllay[strAllay.Length - 1 - i] = s;
}
foreach (string ss in strAllay)
{
Console.Write(ss+" " );
}
Console.ReadKey();
}
}
}
C#數(shù)組排序:
復(fù)制代碼 代碼如下:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 數(shù)組
{
class Program
{
static void Main(string[] args)
{
//輸出一個(gè)數(shù)組里的最大的數(shù)值;
/*
int[] arr = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 };
int max = 0;
for (int i = 0; i < arr.Length - 1; i++)
{
if (arr[i] > max)
{
max = arr[i];
}
}
Console.WriteLine(max);
**/
//按大小順序輸出數(shù)組的值
int[] list = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 ,100,25,38};
/*
for (int i = 0; i < list.Length-1; i++)
{
for (int j = i+1; j < list.Length; j++)
{
if (list[i] > list[j])
{
int temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}*/
/// <summary>
/// 插入排序法
/// </summary>
/// <param name="list"></param>
for (int i = 1; i < list.Length; i++)
{
int t = list[i];
int j = i;
while ((j > 0) && (list[j - 1] > t))
{
list[j] = list[j - 1];
--j;
}
list[j] = t;
}
foreach (int forStr in list)
{
Console.Write(forStr + " ");
}
Console.ReadKey();
}
}
}
希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- C#二維數(shù)組基本用法實(shí)例
- C#使用foreach語句遍歷二維數(shù)組的方法
- C#實(shí)現(xiàn)對二維數(shù)組排序的方法
- c#基礎(chǔ)之?dāng)?shù)組與接口使用示例(遍歷數(shù)組 二維數(shù)組)
- C#數(shù)組排序的兩種常用方法
- C# 數(shù)組查找與排序?qū)崿F(xiàn)代碼
- C#基礎(chǔ)之?dāng)?shù)組排序、對象大小比較實(shí)現(xiàn)代碼
- C#實(shí)現(xiàn)對數(shù)組進(jìn)行隨機(jī)排序類實(shí)例
- C#使用linq對數(shù)組進(jìn)行篩選排序的方法
- C#實(shí)現(xiàn)的二維數(shù)組排序算法示例
相關(guān)文章
-
C#編程中使用ref和out關(guān)鍵字來傳遞數(shù)組對象的用法
這篇文章主要介紹了C#編程中使用ref和out關(guān)鍵字來傳遞數(shù)組對象的用法,在C#中數(shù)組也是對象可以被傳遞,需要的朋友可以參考下 2016-01-01
-
C# 鼠標(biāo)穿透窗體功能的實(shí)現(xiàn)方法
通過以下代碼,在窗體啟動(dòng)后調(diào)用方法SetPenetrate() 即可實(shí)現(xiàn)窗體的穿透功能,有需要的朋友可以參考一下 2013-10-10
-
C# 中的 IReadOnlyDictionary 和 IReadOnlyLis
C# 中的IReadOnlyDictionary和IReadOnlyList是接口,用于表示只讀的字典和只讀的列表,這些接口提供了對集合的只讀訪問權(quán)限,即不允許對集合進(jìn)行修改操作,這篇文章主要介紹了C# 中的 IReadOnlyDictionary 和 IReadOnlyList實(shí)例詳解,需要的朋友可以參考下 2024-03-03
-
C# 復(fù)制與刪除文件的實(shí)現(xiàn)方法
這篇文章主要介紹了C# 復(fù)制與刪除文件的實(shí)現(xiàn)方法的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下 2017-10-10
-
C#將數(shù)字轉(zhuǎn)換成字節(jié)數(shù)組的方法
這篇文章主要介紹了C#將數(shù)字轉(zhuǎn)換成字節(jié)數(shù)組的方法,涉及C#字符串操作的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下 2015-04-04
-
利用Distinct()內(nèi)置方法對List集合的去重問題詳解
這篇文章主要給大家介紹了關(guān)于利用Distinct()內(nèi)置方法對List集合的去重問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧 2019-06-06
最新評論
本文實(shí)例分析了C#數(shù)組反轉(zhuǎn)與排序的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
C#數(shù)組反轉(zhuǎn)
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 數(shù)據(jù)反轉(zhuǎn)
{
class Program
{
static void Main(string[] args)
{
string[] strAllay = { ""};
string s;
for (int i = 0; i < strAllay.Length / 2; i++)//strAllay.Length/2是因?yàn)榻?jīng)過(將數(shù)組的長度值除以2)次就可以將數(shù)組成員進(jìn)行反轉(zhuǎn)了
{
s = strAllay[i];
strAllay[i] = strAllay[strAllay.Length - 1 - i];//如果i等于數(shù)組第一項(xiàng)值()的時(shí)候,將它與最后一個(gè)值()互換。
strAllay[strAllay.Length - 1 - i] = s;
}
foreach (string ss in strAllay)
{
Console.Write(ss+" " );
}
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 數(shù)據(jù)反轉(zhuǎn)
{
class Program
{
static void Main(string[] args)
{
string[] strAllay = { ""};
string s;
for (int i = 0; i < strAllay.Length / 2; i++)//strAllay.Length/2是因?yàn)榻?jīng)過(將數(shù)組的長度值除以2)次就可以將數(shù)組成員進(jìn)行反轉(zhuǎn)了
{
s = strAllay[i];
strAllay[i] = strAllay[strAllay.Length - 1 - i];//如果i等于數(shù)組第一項(xiàng)值()的時(shí)候,將它與最后一個(gè)值()互換。
strAllay[strAllay.Length - 1 - i] = s;
}
foreach (string ss in strAllay)
{
Console.Write(ss+" " );
}
Console.ReadKey();
}
}
}
C#數(shù)組排序:
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 數(shù)組
{
class Program
{
static void Main(string[] args)
{
//輸出一個(gè)數(shù)組里的最大的數(shù)值;
/*
int[] arr = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 };
int max = 0;
for (int i = 0; i < arr.Length - 1; i++)
{
if (arr[i] > max)
{
max = arr[i];
}
}
Console.WriteLine(max);
**/
//按大小順序輸出數(shù)組的值
int[] list = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 ,100,25,38};
/*
for (int i = 0; i < list.Length-1; i++)
{
for (int j = i+1; j < list.Length; j++)
{
if (list[i] > list[j])
{
int temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}*/
/// <summary>
/// 插入排序法
/// </summary>
/// <param name="list"></param>
for (int i = 1; i < list.Length; i++)
{
int t = list[i];
int j = i;
while ((j > 0) && (list[j - 1] > t))
{
list[j] = list[j - 1];
--j;
}
list[j] = t;
}
foreach (int forStr in list)
{
Console.Write(forStr + " ");
}
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 數(shù)組
{
class Program
{
static void Main(string[] args)
{
//輸出一個(gè)數(shù)組里的最大的數(shù)值;
/*
int[] arr = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 };
int max = 0;
for (int i = 0; i < arr.Length - 1; i++)
{
if (arr[i] > max)
{
max = arr[i];
}
}
Console.WriteLine(max);
**/
//按大小順序輸出數(shù)組的值
int[] list = new int[] { 10, 9, 15, 6, 24, 3, 0, 7, 19, 1 ,100,25,38};
/*
for (int i = 0; i < list.Length-1; i++)
{
for (int j = i+1; j < list.Length; j++)
{
if (list[i] > list[j])
{
int temp = list[i];
list[i] = list[j];
list[j] = temp;
}
}
}*/
/// <summary>
/// 插入排序法
/// </summary>
/// <param name="list"></param>
for (int i = 1; i < list.Length; i++)
{
int t = list[i];
int j = i;
while ((j > 0) && (list[j - 1] > t))
{
list[j] = list[j - 1];
--j;
}
list[j] = t;
}
foreach (int forStr in list)
{
Console.Write(forStr + " ");
}
Console.ReadKey();
}
}
}
希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- C#二維數(shù)組基本用法實(shí)例
- C#使用foreach語句遍歷二維數(shù)組的方法
- C#實(shí)現(xiàn)對二維數(shù)組排序的方法
- c#基礎(chǔ)之?dāng)?shù)組與接口使用示例(遍歷數(shù)組 二維數(shù)組)
- C#數(shù)組排序的兩種常用方法
- C# 數(shù)組查找與排序?qū)崿F(xiàn)代碼
- C#基礎(chǔ)之?dāng)?shù)組排序、對象大小比較實(shí)現(xiàn)代碼
- C#實(shí)現(xiàn)對數(shù)組進(jìn)行隨機(jī)排序類實(shí)例
- C#使用linq對數(shù)組進(jìn)行篩選排序的方法
- C#實(shí)現(xiàn)的二維數(shù)組排序算法示例
相關(guān)文章
C#編程中使用ref和out關(guān)鍵字來傳遞數(shù)組對象的用法
這篇文章主要介紹了C#編程中使用ref和out關(guān)鍵字來傳遞數(shù)組對象的用法,在C#中數(shù)組也是對象可以被傳遞,需要的朋友可以參考下2016-01-01C# 鼠標(biāo)穿透窗體功能的實(shí)現(xiàn)方法
通過以下代碼,在窗體啟動(dòng)后調(diào)用方法SetPenetrate() 即可實(shí)現(xiàn)窗體的穿透功能,有需要的朋友可以參考一下2013-10-10C# 中的 IReadOnlyDictionary 和 IReadOnlyLis
C# 中的IReadOnlyDictionary和IReadOnlyList是接口,用于表示只讀的字典和只讀的列表,這些接口提供了對集合的只讀訪問權(quán)限,即不允許對集合進(jìn)行修改操作,這篇文章主要介紹了C# 中的 IReadOnlyDictionary 和 IReadOnlyList實(shí)例詳解,需要的朋友可以參考下2024-03-03C# 復(fù)制與刪除文件的實(shí)現(xiàn)方法
這篇文章主要介紹了C# 復(fù)制與刪除文件的實(shí)現(xiàn)方法的相關(guān)資料,希望通過本文能幫助到大家,讓大家理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-10-10C#將數(shù)字轉(zhuǎn)換成字節(jié)數(shù)組的方法
這篇文章主要介紹了C#將數(shù)字轉(zhuǎn)換成字節(jié)數(shù)組的方法,涉及C#字符串操作的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04利用Distinct()內(nèi)置方法對List集合的去重問題詳解
這篇文章主要給大家介紹了關(guān)于利用Distinct()內(nèi)置方法對List集合的去重問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06