Code bài toán quản lí ,sắp sếp, tìm kiếm sử dụng Queue trong C khai bao queue 2 khoi tao hang doi rong 2 kiem tra hang doi queue rong 2 kiem tra hang doi day 3 them phan tu vao cuoi queue 3 viet ham nhap hang doi 3 viet ham tao input 4 lay mot phan tu ra khoi hang 4 viet ham output 5 loai bo phan tu dau ra khoi dau hang doi 5 tim kiem phan tu theo so k 6 tim kiem mon hoc co luong san pham >10 7 tim san pham co don gia max 7 tim san pham co so luong hang hoa nho nhat 8 bai toan sap xep cac san pham so luong giam dan 8 tinh tien 9 tinh trung binh so luong sp 9 Ham main 10
Mục Lục Code toán quản lí ,sắp sếp, tìm kiếm sử dụng Queue C //khai bao queue //khoi tao hang doi rong // kiem tra hang doi queue rong //kiem tra hang doi day //them phan tu vao cuoi queue //viet ham nhap hang doi //viet ham tao input //lay mot phan tu khoi hang //viet ham output // loai bo phan tu dau khoi dau hang doi .5 // tim kiem phan tu theo so k //tim kiem mon hoc co luong san pham >10 .7 //tim san pham co don gia max .7 //tim san pham co so luong hang hoa nho nhat // bai toan sap xep cac san pham so luong giam dan //tinh tien .9 // tinh trung binh so luong sp .9 //Ham main 10 #include #include #define max 100 struct mypham{ int mamp,soluong,dongia,tongtien; char tenmp[20]; }; //khai bao queue struct queue{ int head,tail,count; mypham node[max]; }; //khoi tao hang doi rong void init(queue &Q){ Q.head=0; Q.tail=-1; Q.count=0; } // kiem tra hang doi queue rong int isEmpty(queue Q){ if(Q.count==0) return 1; return 0; } //kiem tra hang doi day int isFull(queue Q){ if(Q.count==max) return 1; return 0; } //them phan tu vao cuoi queue void push(queue &Q, mypham x) //them phan tu vao cuoi Queue { if (isFull(Q)) printf("Hang doi day !"); else { Q.node[++Q.tail] = x; //tang Rear len va gan phan tu vao Q.count++; //tang so phan tu len } } //viet ham nhap hang doi void nhap(mypham &x){ printf("Moi ban nhap Ma san pham:"); scanf("%d",&x.mamp); fflush(stdin); printf("Moi ban nhap ten san pham:"); gets(x.tenmp); fflush(stdin); printf("Moi ban nhap so luong:"); scanf("%d",&x.soluong); printf("Moi ban nhap don gia:"); scanf("%d",&a); x.dongia = a; b = x.soluong*x.dongia; x.tongtien = b; } //viet ham tao input void input(queue &Q){ int i,n; mypham x; printf("nhap vao so san pham:"); scanf("%d",&n); for(i=0;i