[r]
(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:"; {
cin>>x; if(x>0)
insertrear(l, x); } while (x>0);
}
void taonn(list &l, int n) {
(2)srand(time(NULL)); for (i=0; i<n; i++) {
x = rand()%1000; insertrear(l, x); }
}
//=================== Nhap day dua vao ds co thu tu ============ void nhaptt(list &l)
{
int x;
cout<<"\nNhap day:"; {
cin>>x; if(x>0) {
searchorderlist(l, x, ss); insertpos(l, x);
} } while (x>0); }
//============================= In ds ========================== void inds(list &l)
(3)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); insertpos(l1, x);
deletehead(l); }
(4)}
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);