5 thích 0 k thích
199 đã xem

Please using Templates to create the powerful function insert_sort using insertion sort algorithm that allow the main function below works perfectly: (function show_items(T *items, int size) also need to be created )

int main()
{
    float farr[] = {1.2,6.5,8.3,9.1,5.5,2.6,4.9,3.2,7.9};
    int iarr[] = {9,1,8,5,2,4,3,6,7};
    char carr[]= {'a','b','d','h','g','j','c','e','f'};
    string sarr[]= {"one","five","six","seven","eight","two","three","four","nine"};
    insert_sort(iarr,9);
    cout << "Sorted integer array: ";
    show_items(iarr,9);
    cout<<endl;
    insert_sort(farr,9);
    cout << "Sorted float array: ";
    show_items(farr,9);
    cout<<endl;
    insert_sort(carr,9);
    cout << "Sorted char array: ";
    show_items(carr,9);
    cout<<endl;
    insert_sort(sarr,9);
    cout << "Sorted string array: ";
    show_items(sarr,9);
}

Expected output:

Sorted integer array: 1 2 3 4 5 6 7 8 9
Sorted float array: 1.2 2.6 3.2 4.9 5.5 6.5 7.9 8.3 9.1
Sorted char array: a b c d e f g h j
Sorted string array: eight five four nine one seven six three two

Notice: You may have 100% output, but your code matters!

[Normal] Coding (C++) - đã hỏi trong Introduction to Computer Programming I (C) bởi (9.9k điểm)
ID: 25998 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn

chọn từ khóa lại bởi | 199 đã xem
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.131.166
©2016-2024

Những câu hỏi liên quan

6 thích 0 k thích
0 trả lời
[Normal] Coding (C) - đã hỏi ngày 16 tháng 10 năm 2017 trong Introduction to Computer Programming I (C) bởi thopd (12.1k điểm)
ID: 27173 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 218 đã xem
12,783 câu hỏi
183,443 trả lời
172,219 bình luận
4,824 thành viên