Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (15.6 KB, 4 trang )
<span class='text_page_counter'>(1)</span><div class='page_container' data-page=1>
#include <iostream.h>
#include <iomanip.h>
typedef int elem;
#include "LIST.CPP"
int ss(int x, int y)
{
return x-y;
}
void nhapds(list &l)
{
int x;
cout<<"\nNhap day:";
do {
cin>>x;
if(x>0)
insertrear(l, x);
} while (x>0);
}
void taonn(list &l, int n)
{
srand(time(NULL));
x = rand()%1000;
insertrear(l, x);
}
}
//=================== Nhap day dua vao ds co thu tu ============
void nhaptt(list &l)
{
int x;
cout<<"\nNhap day:";
do {
cin>>x;
if(x>0)
{
searchorderlist(l, x, ss);
insertpos(l, x);
}
} while (x>0);
}
//============================= In ds ==========================
void inds(list &l)
int x;
start(l);
while (!eol(l))
{
getdata(l, x);
cout<<setw(4)<<x;
skip(l);
}
}
//============== Sap thu tu bang phuong phap chen ==========
void saptt(list &l, int (*comp)(elem, elem))
{
list l1;
elem x;
createlist(l1);
while (!emptylist(l))
{
start(l);
getdata(l, x);
searchorderlist(l1, x, comp);
deletehead(l);
}
}
void main()
{
list l;
int n=60;
createlist(l);
nhapds(l);
cout<<"\nDanh sach ban dau: "<<nolist(l)<<" phan tu\n";
inds(l);
saptt(l, ss);
cout<<"\nDanh sach duoc sap: "<<nolist(l)<<" phan tu\n";
inds(l);