1. Bubble Sort (Sắp xếp nổi bọt)
Ý tưởng: Giả sử có mảng có n phần tử. Chúng ta sẽ tiến hành duyệt từ cuối lên đầu,so sánh 2 phần tử kề nhau, nếu chúng bị ngược thứ tự thì đổi vị trí, việc duyệt này bắt đầu từ cặp phần tử thứ n-1 và n. Tiếp theo là so sánh cặp phần tử thứ n-2 và n-1,… cho đến khi so sánh và đổi chỗ cặp phần tử thứ nhất và thứ hai. Sau bước này phần tử nhỏ nhất đã được nổi lên vi trí trên cùng (nó giống như hình ảnh của các “bọt” khí nhẹ hơn được nổi lên trên). Tiếp theo tiến hành với các phần tử từ thứ 2 đến thứ n.
Procedure bubblesort(var amang; Ninteger);
begin
var i,j integer;
for i=2 to N do
for j=N down to i do
if (a[j] a[j-1])
then
hoanvi(a[j-1],a[j]);
end;
begin
var i,j integer;
for i=2 to N do
for j=N down to i do
if (a[j] a[j-1])
then
hoanvi(a[j-1],a[j]);
end;
2. Selection Sort (Sắp xếp chọn)
Ý tưởng: Chọn phần tử nhỏ nhất trong n phần tử ban đầu, đưa phần tử này về vị trí đúng là đầu tiên của dãy hiện hành. Sau đó không quan tâm đến nó nữa, xem dãy hiện hành chỉ còn n-1 phần tử của dãy ban đầu, bắt đầu từ vị trí thứ 2. Lặp lại quá trình trên cho dãy hiện hành đến khi dãy hiện hành chỉ còn 1 phần tử. Dãy ban đầu có n phần tử, vậy tóm tắt ý tưởng thuật toán là thực hiện n-1 lượt việc đưa phần tử nhỏ nhất trong dãy hiện hành về vị trí đúng ở đầu dãy.
Các bước tiến hành như sau:
Bước 1: i=1
Bước 2: Tìm phần tử a[min] nhỏ nhất trong dãy hiện hành từ a[i] đến a[n]
Bước 3: Hoán vị a[min] và a[i]
Bước 4: Nếu i<=n-1 thì i=i+1; Lặp lại bước 2
Ngược lại: Dừng. n-1 phần tử đã nằm đúng vị trí.
Procedure seletionsort(var a:mang; N:byte);
var i,j: byte; min: integer;
begin
for 1:=1 to N-1 do
if (a[j] < a[min] then min:=j;
if (min <> i) then hoanvi (a[min]; a[i];
end;
Procedure hoanvi(var x,y: integer);
var tam:integer
begin
tam:=x
x:=y
y:=tam
end;
var i,j: byte; min: integer;
begin
for 1:=1 to N-1 do
if (a[j] < a[min] then min:=j;
if (min <> i) then hoanvi (a[min]; a[i];
end;
Procedure hoanvi(var x,y: integer);
var tam:integer
begin
tam:=x
x:=y
y:=tam
end;
3. Insert Sort
Procedure insertionsort(var a:mang, N:byte);
begin
var pos,i: byte; x:integer;
for i:=2 to N do
begin
x:=a[i]; pos:=i;
{sap xep tang dan}
while (pos>1 and a[pos-1]>x)do
begin
a[pos]:= a[pos-1]; dec(pos);
end;
a[pos]:= x;
end;
{sap xep giam dan}
while (pos>1)
begin
if(a[pos-1] > x)then
begin
a[pos]:= a[pos-1]; dec(pos);
end;
a[pos]:= x;
4. QuickSort
procedure Quicksort ( Var A: Mang);
Procedure Sort( Left, Right: Integer);
Var
i, j, k: Integer;
Begin
i:= Left;
j:= Right;
k:= A[(Left + Right) Div 2];
Repeat
While A[i] < k Do Inc(i);
While k < A[j] Do Dec(j);
If i <> j Then
Begin
HoanVi(A[i],A[j]);
Inc(i);
Dec(j);
end;
Until i > j;
If Left < j Then Sort(Left,j);
If i < Right Then Sort(i,Right);
end;
Begin
Sort(Left; Right);
End;

Code viet sai be bet. Do chu nhan
chay dc
lúc 07:29 4 tháng 1, 2013
quá dởm
lúc 10:04 18 tháng 1, 2013
Ai giúp bài nào hay hơn coi !!!!!!!!!!!
lúc 10:05 18 tháng 1, 2013
Sắp thi Tin học trẻ rùi
lúc 10:06 18 tháng 1, 2013
It's really a nice and helpful piece of info. I am happy that you just shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.
Take a look at my website ... future quotes
lúc 08:08 24 tháng 3, 2013
If you want to take a great deal from this piece of writing then you have to apply such techniques to your won
website.
Look at my web blog :: commitment quotes
lúc 13:19 26 tháng 3, 2013
Hi there! I could have sworn I've been to this blog before but after checking through some of the post I realized it's new to me.
Anyhow, I'm definitely delighted I found it and I'll be bookmarking and checking back frequently!
my website :: genghis khan quotes
lúc 19:42 26 tháng 3, 2013
My partner and I stumbled over here different web address and thought I may as
well check things out. I like what I see so now
i am following you. Look forward to finding out about your web
page repeatedly.
Check out my web blog thanks quotes
lúc 20:54 26 tháng 3, 2013
Peculiar article, totally what I needed.
Also visit my site ... future quotes
lúc 00:03 27 tháng 3, 2013
When I originally commented I appear to have clicked on the -Notify me
when new comments are added- checkbox and
from now on each time a comment is added I recieve four emails with
the same comment. There has to be a means you can remove me from that service?
Thanks a lot!
Also visit my site william shakespeare quotes
lúc 01:48 27 tháng 3, 2013
Excellent article. I am dealing with some of these issues as well.
.
Here is my web-site - sylvia plath quotes
lúc 02:12 27 tháng 3, 2013
An outstanding share! I have just forwarded this onto a colleague
who was doing a little research on this. And he in fact bought me dinner because I
discovered it for him... lol. So let me reword this...
. Thank YOU for the meal!! But yeah, thanx for spending some time to
discuss this subject here on your web page.
Here is my website :: depressing quotes
lúc 22:39 27 tháng 3, 2013
I am not sure where you're getting your information, but great topic. I needs to spend some time learning more or understanding more. Thanks for wonderful info I was looking for this information for my mission.
my web blog; understanding quotes
lúc 06:55 28 tháng 3, 2013
I know this if off topic but I'm looking into starting my own weblog and was curious what all is required to get setup? I'm assuming having a blog
like yours would cost a pretty penny? I'm not very internet smart so I'm not 100% sure. Any suggestions or advice would be greatly appreciated. Appreciate it
Feel free to visit my web blog - tired quotes
lúc 14:17 2 tháng 4, 2013
Keep on working, great job!
Feel free to visit my web blog; frida kahlo quotes
lúc 01:38 3 tháng 4, 2013
Hi! I just wanted to ask if you ever have any trouble with hackers?
My last blog (wordpress) was hacked and I ended up losing months of hard
work due to no backup. Do you have any methods to protect against hackers?
Look at my web site - sylvia plath quotes
lúc 03:54 3 tháng 4, 2013
code sai rất nhiều, lướt sơ qua thì bubblesort,selectionsort đã sai thuật toán,chưa tính đến lỗi cú pháp, mình hoan nghênh tinh thần chia sẻ tuy nhiên khi post bài thì chỉ nên post những gì mình thực sự hiểu hoặc nội dung mình đã kiểm chứng tính đúng đắn đối với code chương trình.
lúc 10:37 27 tháng 4, 2013
chịu thôi
lúc 10:50 30 tháng 5, 2013
I read this article fully concerning the resemblance of most recent and previous technologies,
it's remarkable article.
Stop by my webpage; on line wills
lúc 00:51 5 tháng 6, 2013
Excellent way of explaining, and nice article to obtain facts about
my presentation subject matter, which i am going to present
in college.
My website ... how to get a boy to like you
lúc 05:04 6 tháng 6, 2013
Hi! I'm at work browsing your blog from my new iphone 4! Just wanted to say I love reading through your blog and look forward to all your posts! Keep up the great work!
Also visit my blog post; tips to make a guy fall in love
lúc 16:32 9 tháng 6, 2013
I always spent my half an hour to read this website's articles or reviews daily along with a cup of coffee.
Feel free to visit my web site ... new cellulite treatment
lúc 14:19 12 tháng 6, 2013
xem chả hiểu gi
lúc 14:46 14 tháng 7, 2013
bài cùi bắp vãi,,còn viết cả trên chương trình con nữa vl
lúc 22:07 12 tháng 8, 2013
ai ra cái đề kho khó xem nào
đề này để tui đi thi tin học trẻ 100/100 à dễ vl
ÍT RA CŨNG PHẢI CÓ NHỮNG THUẬT TOÁN NHƯ GUINES,PHALOS chứ
lúc 14:38 4 tháng 1, 2014
Cho mình email or nick fb giúp mình về pascal dc k ?
lúc 19:31 21 tháng 4, 2014
prada shoulder bag
Its such as you learn my mind! You seem to grasp so much about this, like
you wrote the e-book in it or something. I feel that you
can do with some p.c. to power the message house a little bit, however other than that, this
is magnificent blog. A fantastic read. I'll certainly
be back.
lúc 07:54 12 tháng 6, 2014
Các bạn giỏi hơn ngta thì tự đi mà viết lại gt của mình. Đây chỉ là gt thôi mà đâu phải code pascal sẵn đâu mà cho vào ctr làm sao nó chạy được luôn chứ. K biết biến của ng khác thanhô của mình mà chỉ biết đi ba hoa nói bậy thế thì chắc cũng chả ra j
lúc 22:53 9 tháng 8, 2014
quicksort sai be bét...cho dãy 1 2 3 4 5 6 7 8 9 10 ... làm quicksort là lập vô tận cho thấy mẹ luôn
lúc 17:51 1 tháng 12, 2015
nhập dãy số rồi sắp xếp các ssnt rồi cộng lại rồi roi loz + cac
lúc 16:12 2 tháng 5, 2018
:L
lúc 14:24 31 tháng 7, 2018
chả hiểu
j hết
lúc 15:44 8 tháng 3, 2019
các bạn phải tạo đc hàm mà bài cho sẵn kia nó chưa lm chứ. bài đó chỉ tóm tắt thôi chứ viết ra khá dài đấy. còn nếu hok chưa cao thì có thể nhờ người chuyên môn giảng giải chứ đem bài người khác ta swear thì ko nên. Thank you
lúc 08:45 10 tháng 9, 2019
như cục cứt sai tét lét rồi WTF bitch!!!!!!!!!!!!!!!!!!!!!!!
lúc 08:46 30 tháng 10, 2020
? xem tham khao thoi ma
lúc 22:01 17 tháng 2, 2022
Thuật toán chưa check, về code không có vấn đề, nó được viết bằng version mới, nên cho phép khai báo biến động trong body.
Mình đang sài delphi bản tokyo.
lúc 11:22 15 tháng 11, 2024
code sai vl
lúc 17:12 30 tháng 12, 2024
Đăng nhận xét