Bubble sort - Free Pascal wiki

文章推薦指數: 80 %
投票人數:10人

unit UBubbleSort; interface type // data type TItemBubbleSort=integer; procedure BubbleSort( var a: array of TItemBubbleSort ) ... BubblesortFromFreePascalwikiJumptonavigationJumptosearch │ English (en)│ suomi (fi)│ français (fr)│ Bubblesortisasimplesortingalgorithm. Contents 1Characteristics 2UnitUBubbleSort 3Exampleofusage 4Seealso Characteristics Veryslow Suitableonlyforsmallquantitiessorting Fastonlywhenthearrayisnearlysorted UnitUBubbleSort unitUBubbleSort; interface type //datatype TItemBubbleSort=integer; procedureBubbleSort(vara:arrayofTItemBubbleSort); implementation procedureswap(vara,b:TItemBubbleSort); var temp:TItemBubbleSort; begin temp:=a; a:=b; b:=temp; end; procedureBubbleSort(vara:arrayofTItemBubbleSort); var n,newn,i:integer; begin n:=high(a); repeat newn:=0; fori:=1tondo begin ifa[i-1]>a[i]then begin swap(a[i-1],a[i]); newn:=i; end; end; n:=newn; untiln=0; end; end. Exampleofusage uses UBubbleSort ... var a:array[0..100]ofinteger; begin ... BubbleSort(a); ... Seealso COMP1Revise&Learn :BubbleSort Retrievedfrom"http://wiki.freepascal.org/index.php?title=Bubble_sort&oldid=142736" Category:SortNavigationmenuPageactionsPageDiscussionViewsourceHistoryPageactionsPageDiscussionMoreToolsInotherlanguagesPersonaltoolsCreateaccountLoginNavigationMainPageDocumentationFAQDownloadsGlossaryIndexRecentchangesRandompageHelpToolsWhatlinkshereRelatedchangesSpecialpagesPrintableversionPermanentlinkPageinformationSearch Thispagewaslasteditedon27January2021,at21:47.Contentisavailableunderunlessotherwisenoted.PrivacypolicyAboutFreePascalwikiDisclaimers



請為這篇文章評分?