1. Trang chủ
  2. » Luận Văn - Báo Cáo

hoa cuong có thì sử dụng – thích thì lao vào

6 7 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Nội dung

[r]

(1)

Mo ta:

typedef struct {

int key; float value; } elem;

//======Tong hop theo khoa key tren dslk khong thu tu======= void tonghop(list &l)

{

nodeptr p, q, c; if (l.count==0) return; q = l.head;

while (q!=NULL) {

p = q; c = q->next; while (c!=NULL) {

if (q->data.key==c->data.key) {

q->data.value+=c->data.value; if (c->next==NULL) l.rear = p; p->next = c->next;

(2)

else

p = c; c = p->next; }

q = q->next; }

}

//======Tong hop theo khoa key tren dslk co thu tu======= void tonghoptt(list &l)

{

nodeptr q, c;

if (l.count==0) return; q = l.head;

while (q!=NULL) {

c = q->next;

while (c!=NULL && q->data.key==c->data.key) {

q->data.value+=c->data.value; if (c->next==NULL) l.rear = q; q->next = c->next;

(3)

} q = c; }

}

//======Tach dslk dslk theo dieu kien ======== void tach(list &l, list &l1, list &l2)

{

nodeptr c, c1, c2, q1, q2; l1.count = l2.count = 0; c1 = q1 = new node; c2 = q2 = new node; c = l.head;

while (c!=NULL) {

if (c->data.value>=5) {

c1->next = c; c1 = c; l1.count++; }

else {

(4)

}

c = c->next; }

c1->next = c2->next = NULL; l1.head = q1->next;

l2.head = q2->next;

l1.rear = (l1.head==NULL? NULL:c1); l2.rear = (l2.head==NULL? NULL:c2); delete q1;

delete q2;

l.head = l.rear =NULL; l.count = 0;

}

//Tach dslk dslk theo dieu kien tong quat hon void tach(list &l, list &l1, int (*cond(elem))

{

nodeptr c, c1, c2, q1, q2; int n=0;

l1.count = l2.count = 0; c1 = q1 = new node; c2 = q2 = new node; c = l.head;

(5)

if (cond(c->data)) {

c1->next = c; c1 = c; l1.count++; }

else {

c2->next = c; c2 = c; n++; }

c = c->next; }

c1->next = c2->next = NULL; l1.head = q1->next;

l.head = q2->next;

l1.rear = (l1.head==NULL? NULL:c1); l.rear = (l.head==NULL? NULL:c2); delete q1;

delete q2; }

(6)

{

return x.value<4; }

int tb(elem x) {

return x.value<6; }

int kha(elem x) {

return x.value<8; }

list l, lk, lkha, ltb; // Loi goi de tach

Ngày đăng: 20/04/2021, 01:36

w