#include #include #define max_size 100 using namespace std; void tao_mang(int A[],int &n); void xuat_mang(int A[],int n); int gia_tri_lon_nhat(int A[],int n); int gia_tri_nho_nhat(int A[],int n); int tim_kiem(int A[],int n,int x); void them_phan_tu_vao_cuoi(int A[],int &n,int x); void chen(int A[],int &n,int vt,int gt); void xoa(int A[],int &n,int vt); void sap_xep(int A[],int n); int main() { int A[max_size],n; int tiep, gtln, gtnn; int vt,x; do { cout<<"\n\n\t vui long chon cac chuc nang sau: "; cout<<"\n\n1.tao day so"; cout<<"\n2.hien thi day so"; cout<<"\n3.tim max"; cout<<"\n4.tim min"; cout<<"\n5.tim phan tu x"; cout<<"\n6.bo sung phan tu"; cout<<"\n7.chen phan tu vao vi tri bat ki"; cout<<"\n8.xoa phan tu bat ki"; cout<<"9.sap xep day so"; cout<<"10.thoat"; int lua_chon; cout<<"\n\nlua chon chuc nang: "; cin>>lua_chon; while(lua_chon<1 || lua_chon >10) { cout<<"\n\t chon lai chuc nang: "; cin>>lua_chon; } switch(lua_chon) { case 1: //tao mang cout<<"\n\t nhap vao so luong phan tu: "; cin>>n; while(n<1 || n>max_size) { cout<<"\n\t nhap lai so luong phan tu: "; cin>>n; } tao_mang(A,n); break; case 2: cout<<"\n\n\t\t DAY SO CUA MANG LA"; xuat_mang(A,n); break; case 3: //gia tri lon nhat gtln=gia_tri_lon_nhat(A,n); cout<<"\n\n\t gia tri lon nhat cua mang la: "<>x; while(x<0) { cout<<"\n\nnhap lai so nguyen x can tim: "; cin>>x; } vt=tim_kiem(A,n,x); if(vt!=-1) { cout<<"\n\tvi tri xuat hien la: "<>them; while(them<0) { cout<<"\n\nnhap lai phan tu muon them o cuoi: "; cin>>them; } them_phan_tu_vao_cuoi(A,n,them); xuat_mang(A,n); cout<<"\n\n-----------------------------------------"; break; case 7: //chen vao vi tri bat ki int vt_chen,gt; cout<<"\n nhap vao vi tri can chen: "; cin>>vt_chen; while(vt_chen<=0 || vt_chen>n+1) { cout<<"\n\nnhap lai vi tri can chen: "; cin>>vt_chen; } cout<<"\n nhap vao gia tri can chen: "; cin>>gt; while(gt<0) { cout<<"\n\nnhap lai gia tri can chen: "; cin>>gt; } chen(A,n,vt_chen,gt); cout<<"\n\n\t mang sau khi chen la "; xuat_mang(A,n); cout<<"\n\n-----------------------------------------"; break; case 8: //xoa vi tri trong mang int vt_xoa; cout<<"\nnhap vao vi tri can xoa: "; cin>>vt_xoa; while(vt_xoa<=0 || vt_xoa>n) { cout<<"\n\nnhap lai vi tri can xoa: "; cin>>vt_xoa; } xoa(A,n,vt_xoa); xuat_mang(A,n); cout<<"\n\n-----------------------------------------"; break; case 9: //sap xep sap_xep(A,n); xuat_mang(A,n); cout<<"\n\n-----------------------------------------"; break; case 10: return 0; } cout<<"\n\nban muon tiep tuc khong: \n1.tiep\n2.khong"; cin>>tiep; } while(tiep==1); return 0; } void tao_mang(int A[],int &n) { for(int i=0; i>A[i]; } } void xuat_mang(int A[],int n) { for(int i=0; imaxx) { maxx=A[i]; } } return maxx; } int gia_tri_nho_nhat(int A[],int n) { int minn=A[0]; for(int i=1; i=vt-1; i--) { A[i+1]=A[i]; } A[vt-1]=gt; n++; } void xoa(int A[],int &n,int vt) { for(int i=vt-1; i<=n-1; i++) { A[i]=A[i+1]; } n--; } void sap_xep(int A[],int n) { int tg; for(int i=0; iA[j]) { tg=A[j]; A[j]=A[i]; A[i]=tg; } } } }