Untitled
unknown
c_cpp
3 years ago
3.5 kB
10
Indexable
#include <iostream>
#include <cstring>
#include <algorithm>
#include <time.h>
using namespace std;
struct congViec {
int maSo;
char* tenCongViec = new char[20];
int thoiGian;
char* nguoiThucHien = new char[30];
int doUuTien;
};
void Xuat(congViec a) {
cout << "===================================\n";
cout << a.maSo << endl;
cout << a.tenCongViec << endl;
cout << a.thoiGian << endl;
cout << a.nguoiThucHien << endl;
cout << a.doUuTien << endl;
}
struct node {
congViec data;
node* next;
};
struct Stack {
node* head;
};
Stack createStack(Stack& a) {
a.head = NULL;
return a;
}
Stack push(Stack& a, congViec& x) {
node* tmp = new node;
tmp->data = x;
tmp->next = a.head;
a.head = tmp;
return a;
}
Stack pop(Stack& a) {
if (a.head) return a;
node* tmp = a.head;
a.head = a.head->next;
delete tmp;
return a;
}
congViec top(Stack& a) {
return a.head->data;
}
Stack KhoiTaoNgauNhien(Stack& a) {
srand(time(NULL));
int n = 1;
char Ten[20][20]{ "Giang","Ky","Phi","Tan","Van","Vuong","Cong","Hien","Linh","Ngoc",
"Huy","Khang","Bao","Minh","Phuc","Anh","Khoa","Phat","Äat","Khoi" };
char Ho[20][20] = { " NGUYEN"," TRAN"," LE"," PHAM"," HOANG"," VO"," PHAN"," TRUONG"," BUI"," DANG",
" DO"," NGO"," HO"," DUONG"," DINH"," DOAN"," LAM"," MAI"," TRINH"," DAO" };
char Job[10][20] = { "Cau ca","Di boi","Lao cong","Cong nhan","Nhan vien",
"Ky su","Giao vien","Dau bep","Bao ve","Boi ban" };
for (int i = 0; i < n; i++) {
congViec tmp;
tmp.maSo = rand();
strcpy(tmp.tenCongViec,strcat(Job[rand() % 10],"\0"));
tmp.thoiGian = rand() % 180 + 180;
strcpy(tmp.nguoiThucHien,strcat(strcat(Ten[rand() % 20], Ho[rand() % 20]),"\0"));
tmp.doUuTien = rand() % 10 + 1;
Xuat(tmp);
a = push(a, tmp);
}
return a;
}
// bool sosanh1(congViec a,congViec b){
// return a.thoiGian>b.thoiGian;
// }
// congViec timCaoNhat(Stack& a){
// node* p=a.head;
// congViec tmp[100];
// int n=0;
// while(p->next!=NULL){
// tmp[n]=p->data;
// p=p->next;
// n++;
// }
// sort(tmp,tmp+n,sosanh1);
// if(tmp[0].thoiGian==tmp[1].thoiGian){
// congViec ngoaiLe;
// ngoaiLe.maSo=0;
// char tmp1[20]="khong co";
// ngoaiLe.tenCongViec=tmp1;
// ngoaiLe.thoiGian=0;
// char tmp2[20]="dung NGUYEN";
// ngoaiLe.nguoiThucHien=tmp2;
// return ngoaiLe;
// }
// return tmp[0];
// }
// Stack capNhap300(Stack& a){
// node* p=a.head;
// while(p->next!=NULL){
// if(p->data.thoiGian>300){
// p->data.thoiGian=300;
// }
// }
// return a;
// }
// Stack sort(Stack& a){
// for(node* i=a.head;i!=NULL;i=i->next){
// for(node* j=i->next;j!=NULL;j=j->next){
// if(i->data.doUuTien<j->data.doUuTien) swap(i->data,j->data);
// }
// }
// return a;
// }
void printStack(Stack a) {
node* p = a.head;
while (p != NULL) {
Xuat(p->data);
p = p->next;
cout << "--------------" << endl;
}
}
int main() {
Stack a;
createStack(a);
KhoiTaoNgauNhien(a);
printStack(a);
return 0;
}Editor is loading...