0 thích 0 k thích
4.9k đã 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!

[Exercise] Coding (C++) - đã hỏi trong C++
ID: 24896 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn

đã sửa bởi | 4.9k đã xem
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help

27 Trả lời

0 thích 0 k thích
Hidden content!
int main()
{
* ***** ** * ** ** farr[] = **** * * * **
* ** **** * * *** ** ** iarr[] = {9,1,8,5,2,4,3,6,7};
** *** * * * *** ** *** * * carr[]= ** ** * ** ** ** **
** * ** * ***** * * ** * * sarr[]= * * *** ****** ** * * **** * * ** *** * ** ***** * * ** *** ***** * * *** * * * ******* * ***** * * * * * *** ** **** ** *** **
**** ** * * * ** ** * * * * * * *
** * ******* *** * * << "Sorted integer array: ";
*** * * * * *** ****** ** *
* * * * * * * **** * *** *** * *
** ** * *** * *** ** * *
* * * ** ** ** * * ******* * << "Sorted float array: ";
* *** * * ** ****** *** ** *
* * ** *** * *** **** ** * * **** *
** * ** * * ***** ** *** *** * *** **
** *** * ** * ***** << "Sorted char array: ";
** * * *** ** * *** ** * ** ** *
* * ** ** **** *** ** ** * *** *** ***
** *** *** * *** ** *** * * *** *
* * * * ** * * ****** * ** << "Sorted string array: ";
*** ** * ** **** ** ** * * *
}
trả lời
0 0
prog.cpp: In function 'int main()':
prog.cpp:6:5: error: 'string' was not declared in this scope
     string sarr[]= {"one","five","six","seven","eight","two","three","four","nine"};
     ^~~~~~
prog.cpp:7:23: error: 'insert_sort' was not declared in this scope
     insert_sort(iarr,9);
                       ^
prog.cpp:8:5: error: 'cout' was not declared in this scope
     cout << "Sorted integer array: ";
     ^~~~
prog.cpp:9:22: error: 'show_items' was not declared in this scope
     show_items(iarr,9);
                      ^
prog.cpp:10:11: error: 'endl' was not declared in this scope
     cout<<endl;
           ^~~~
prog.cpp:19:17: error: 'sarr' was not declared in this scope
     insert_sort(sarr,9);
                 ^~~~
0 thích 0 k thích
Hidden content!
#include * * ***

using namespace std;

template <class T>
void insert_sort(T *items, int size)
{
*** ** * * ** ** **** * x;
*** * * ****** * ** * * j;
*** * *** *** * i=1; i<size; i++)
* * * * ** ** *
* ** * ** ** ** ****** * ***** ** * **** * = items[i];
** * **** * * * ** ** * *** * * ** = i - 1;
*** * * ** * **** ** * * * *** *** (j >= 0 ****** *** items[j] > x)
*** ***** * **** * * * * ** * *** * *****
** ** * ***** * * **** * * ** * * * * * * ** *** * ** * ** *** * * = items[j];
* * * *** **** * ** * **** * ***** * * * * * * * *** = j - 1;
* ** *** ** ** * * * **** * * * **
* * ** * ** ** * ** * ** * ** * ** ** *** **** *** * = x;
*** ** ** * **** * ***
}

template <class T>
void show_items(T *items, int size)
{
* ** * * **** * ** * ** * i=0; ** * ** * i++)
* ** * * * ** * ** *** ** *** * ** * ** ** ***** ** * items[i] << " ";
** * * ***** ** * * * * * *** items[size-1];
}

int main()
{
** * ** **** * *** * ** farr[] = * ****** *** **
** *** ** * * ** ** * iarr[] = ** *** ****
*** **** * ** ***** *** carr[]= * ** * * * *** * * ***
**** ** * * ** * * * *** sarr[]= * * ** * * * ** * *** * *** * * **** ** ** * ****** * * ** * ******* * * **** * * * ** **** ** * * *** ** * ** * ** *
* **** ** * *** * * ** * **
* * **** * * ** * ** ** ** * * * integer array: ";
* * ** * * ** * ** ******* **
* * * **** * ** ********** ** **
* ***** * ** ** *** * * * **
* **** *** * * ** << "Sorted float array: ";
* * * *** *** * ** * * ** * * *
** * ** * * ***** * * * ** **
* *** * * * ** * * *** *** *
** * * * *** * * ****** << "Sorted char array: ";
** * * * **** ** * * * ** ** *
** * ** **** ***** * ** ***** *
* * * * * * * * * * **** ** ** * ***
** * ** ** * *** * *** * **** *** **** string array: ";
*** ** **** * ** *** **** * * **
}
trả lời bởi (-189 điểm)
0 thích 0 k thích
Hidden content!
#include ** * **

using namespace std;

template <class T>
void insert_sort(T *items, int size)
{
******* * ** ** * * * * * x;
** * * ** ** ** * * j;
* ** * * * ***** * * * **** i=1; i<size; i++)
* ** **** * ** ** * ** **
** * **** *** * ** ******* ** * * ********** *** * = items[i];
* * * * * *** ** * **** ** *** **** * * ** = i - 1;
* * ** * * * * * * * ** * *** ** * ** (j >= 0 ****** ** items[j] > x)
* * ** ** **** ** ** ***** * * ** * * ****
*** * ** ****** * ** ** ** * ** *** * *** ***** ** ** *** * * * = items[j];
* ***** ** * ** * * * * *** * *** ***** * **** * ** * * *** = j - 1;
* * ** * ** ** * * *** ** ** * ** * * ** * ****
* **** * * *** * * ** ****** * * * ** ** ***** ** * = x;
* ** * * ** *
}

template <class T>
void show_items(T *items, int size)
{
***** *** * ** * ** * * * ** i=0; ** ** * i++)
* * * * ** * * * **** * * * ** ** * ** * items[i] << " ";
**** * ** ** * ** *** ** * items[size-1];
}

int main()
{
*** **** * *** ** * * farr[] = *** * * * **** ****
* * ** *** ****** ** * iarr[] = * * * * **
* * * * * * * ** * *** carr[]= ** **** **** * ***
* * ** ** * * ** * sarr[]= * * ** ** ***** * * ** ** * ****** * ** ** * * **** * * * *********** * **** * * *** ** * ** ** ** ** ** ** *** **
**** *** ** *** *** *** * * * *
* ** *** * * * * ** * * * ****** *** integer array: ";
* * ** **** ** * * ***** *** * *
** * * *** * * ** ** * ***
* ** * ******* * *** * ** ****
* * *** ** * * * * ** * << "Sorted float array: ";
*** * *** **** * *** * * *
**** * *** *** ** * *** * ** * *
* * ** * ** * * * * **** ** * ***** **
** ** ** * * * * << "Sorted char array: ";
* * * ** ** * * *** ** * ** *** * *
* ** * *** ***** * * ** * * ** *
** ** * * * * ** ** * *
* ****** * *** * ******* ** *** * ** * ** * string array: ";
* * *** * *** * * *** *
}
trả lời bởi (-298 điểm)
0 thích 0 k thích
Hidden content!
#include ** *** *



using namespace std;



template <class T>

void insert_sort(T *items, int size)

{
*** *** ** * * x;
* * ** * ** * ** ** j;
* *** ** * * * ** ** i=1; i<size; i++)
* ** * * * ** ***** **
* ** * * * ** * ** ** *** * ***** * * ** = items[i];
* * ****** * * * * * ** ***** ** * **** = i - 1;
** *** * **** ** * * ** * ** ******* * ** ** * (j >= 0 * ** *** items[j] > x)
**** * * * ****** * *** ******** * *** **
** * * * * *** * ** * ****** * * ** * *** ** ** * ** * *** * * * = items[j];
* * ******** * **** ***** **** ******* ** **** ** ** **** * = j - 1;
*** ** ** *** * ** *** * ** * ***** ** *** **
* * * * **** * * *** * * ** **** *** ***** * = x;
******* * * **** * ******

}



template <class T>

void show_items(T *items, int size)

{
* * * * **** *** * ** **** * i=0; * ** * * * i++)
***** ** ***** * * ** **** ** * * *** *** * * * **** * * items[i] << " ";
* ** * * ****** ** * * *** items[size-1];

}



int main()

{
* *** * * ** * ** * **** ** farr[] = * * ** * **** * * **
* ** * ** ** * * * iarr[] = **** **
*** ** ******** ** * carr[]= ** * * *******
* * * ** ** * * * * * ** * * * sarr[]= * ** ** ** * *** ** **** ** ** ** *** * * * * ***** * * * * * * ** *** *** * **** * **** ** * **** * ** *
*** **** ** *** ** * * ** *
******** ** * * * * * * * ** *** *** integer array: ";
* ** * * **** ****** * ***** * * *
* ** ** ** ****** * ** ** * ***
** * * * ** * ** ***** * **
* ** ** * ***** * ** << "Sorted float array: ";
* *** * ** ****** * *** ** *
* * *** ** * * * *** * * ** ** *
** *** ** * *** ** * *** * ** *** **
* * ** * * * * * *** << "Sorted char array: ";
* **** * * ** * * * **** ****
* ** ** ***** *** ***** * **** * * * *
* * * * ** ** * * * * * **
*** **** * ** ***** ** ** * * *** string array: ";
* ***** ** * ***** * * **

}
trả lời bởi (237 điểm)
0 thích 0 k thích
Hidden content!
#include *** ** * * **



using namespace std;



template <class T>

void insert_sort(T *items, int size)

{
* * *** ***** **** **** x;
*** ** ** ** ** ****** *** * j;
****** * * ** * * ** ** * i=1; i<size; i++)
**** ******* * * * ** *
* * *** ** * **** * * ** * * * **** ***** ** = items[i];
** ***** * ** * *** ** * *** * *** ** * = i - 1;
**** * * **** ** ** *** ** ** * ** * * * (j >= 0 * *** * * * items[j] > x)
*** ** * * **** ******* * ** * *** ** * ** *****
* ** **** *** *** * * * *** * ** * * * *** ** * * * *** * * * *** = items[j];
*** **** *** * ** * * * ** * * ** * * * * * * * * = j - 1;
* * ** * * * * * * * *** *** * * * *** *
** *** * * ** **** ** ** * * * ** ** ** **** = x;
* *** **** ** * * ***

}



template <class T>

void show_items(T *items, int size)

{
** * ******** ******** * * i=0; * * ** * i++)
* * * *** ** ** ** **** ** ** ** * **** * ** ** ** items[i] << " ";
* ** **** * ** ***** *** ** * * items[size-1];

}



int main()

{
*** * * * **** **** farr[] = * * * * * * * **
** * * * * * * iarr[] = * *
* ** ***** * **** ** **** carr[]= ** **** ** *** ***
* * * * ****** * *** ** * * sarr[]= * *** ** * *** *** * *** ** * * * * ** * * ***** *** * *** * ** ********* ** * *** ** ** * * * * ** * * * ** * ***
***** ** *** *** * * ** ** **
* **** * ********* * ** * * * * ** * * integer array: ";
**** *** * * **** * *** * ******
*** * **** * **** * * ** **** ***
*** * ****** ** * * ** * ** * ** ****
* ** *** ** * * * ** << "Sorted float array: ";
* **** ** * ***** * ***** * *
*** ** * **** * * *** * ***** * *
** * ** *** * * ** **** ***
* *** *** **** ***** * * << "Sorted char array: ";
* ******** ** ** ** **** *
*** ** * ** * **** * ** * ** *
**** * * *** ******* ** ** *
* * ** **** ** ** *** ** * * **** * ** ** * string array: ";
* ** * *** * *** * ****** * ** ** *

}
trả lời bởi (-215 điểm)
0 thích 0 k thích
Hidden content!
#include ** ** ** * *



using namespace std;



template <class T>

void insert_sort(T *items, int size)

{
** * * *** * ** * x;
** * **** * ** * * ***** j;
* ***** *** * * * * ******** ** * i=1; i<size; i++)
** ** * ** **** *
* * * * * * *** * * ** * ***** * *** * ****** * = items[i];
*** * * * ** * * * * * * * ** * **** ****** = i - 1;
** * ** ** * ** ** ** *** * ** * ** * * ** * (j >= 0 * ** * * ** items[j] > x)
* * * **** ** * * **** **** ** ****** **
*** ******** ***** * * ** * * * *** * *** * ***** *** ** * ****** *** = items[j];
* * * * * ** *** ** *** * *** * ** **** *** ** * ** *** = j - 1;
**** * ******** ** * * * *** * *** *
** * ** *** * * * * * *** * * ** ** * * * *** = x;
* * ** ****** ** * *

}



template <class T>

void show_items(T *items, int size)

{
** ** ***** * * * ** ** *** i=0; *** * ** i++)
* ** * **** * * *** * ** * * ** * ** ** * ****** ** * * * items[i] << " ";
** *** * ******* ** * ** ** **** ** *** items[size-1];

}



int main()

{
*** **** * * * * * farr[] = *** * ** * * **** * *
* ** *** * **** *** * iarr[] = * * ** * *
** * ** *** ** * * ** * carr[]= * * * ***** * *
** * * * *** ** * *** sarr[]= ** ***** **** ** *** ** * **** ***** * *** *** ** ** * ** * ** *** ** *** ** ** ** ** ******* * *** * *** * *** ** * * * *
* ** * * ** * * * * *** ** ***
*** * * ** * **** ** * * **** ***** * integer array: ";
* ** *** * * * * * * ** * * * ***
** * * * * * *** ** * * ****** **
* * ** * ** ** ****** **** *
* * * *** * ** * << "Sorted float array: ";
* * * ** ***** * *** * ** ** **
* **** * * *** **** ** * ***** * * * * *
* * * * * ** * **** * *** * *
** ** * *** *** * ** * * *** << "Sorted char array: ";
**** * *** * * ** * * * ***
* ** *** ** * ** ** ** * ** ** *
** **** *** * ** * ** * *
*** * * ** * * * * ****** ** * *** * * * string array: ";
** **** *** * **** *** * ** * * *

}
trả lời bởi (126 điểm)
0 thích 0 k thích
Hidden content!
#include<iostream>

using namespace std;

template <class sort>

void insert_sort(sort a[],int n)

{
** * * * * * ** *** ** ** ** * x;
* ***** * * *** ** * ** i,j,k;
** *** ** * ** * * *** * ** *** *** ***
***** **** *** ** *** * ** *** * * ** * **
* * * * ** * * * * * ** ** * ** *** ** * * *
* ** *** * * * * ** **** ** * * * * * ** * * ** * && a[j]>x)
* ** ***** * ** ** ** *** * ******** *** * **
** *** ** *** * * * **** ** * * * * ** *** **** ** ** *** * * ** * * *
*** *** ** * **** * * ** * ** * * * ** * * ** **** * * ** * * ** * *
**** * * * * * * * * *** ***** * ** ****
** ** * * * * * * * *** *** * ** * * * * * * ***
** * * *** * * **** * *

}

template <class sort>

void show_items(sort a[],int n)

{
* ****** * * * * ** * ** i;
* * * * * * * * * *** * ** * * * ***
** ***** ** * *** *** * ******* ** * *
* ** **** ** * * * ** * ** * * * * * **** *** ** * *** ** ** * * *** ****** * ";
** * *** * ***** * * ****** * ** ** **** *
* * ** * * *** * ***** * *** * ** **** ** ** ** **** ** * * ** * * * *
*** * * **** *** ******

}

int main()

{
* * *** ** ** ***** ** * * * farr[] = {1.2,6.5,8.3,9.1,5.5,2.6,4.9,3.2,7.9};
* * ***** * ***** ** *** iarr[] = {9,1,8,5,2,4,3,6,7};
* * * * * * * ** * carr[]= {'a','b','d','h','g','j','c','e','f'};
* ** **** ** ** ** sarr[]= ** * **** * ** * * * * * * ** ****** * * * * **** * * * *** ** * ** * * * ** * * *** * * ***** * ** ***** *** ** * ***
* * ** *** ***** * * * * * **
* * * * * * * * * * **** << "Sorted integer array: ";
* **** ** ****** * **** * * * *** **
** * ** *** * * * ** **** *** * *
* *** ***** *** * *** *
* * * * *** * * ** * ** * << "Sorted float array: ";
*** * *** *** * * ** * *** ***
*** * ** * * * * *** ** * **
** *** * * * ** ** ** **
**** ** * * ** * *** << "Sorted char array: ";
* * ** **** * ** **** ** * * * ** ** *
* * ** * **** * **** * ** ** *
* ** * *** * * ** ***** ** **
** * ** ** * ***** ** *** << "Sorted string array: ";
** * ** ** * * * ** ** *

}
trả lời bởi (-249 điểm)
0 thích 0 k thích
Hidden content!
using namespace std;

template <class sort>

void insert_sort(sort a[],int n)

{
** ** * **** ** * * x;
* ** **** ** * *** i,j,k;
***** * *** * *** ** * * * *
* * * *** ** *** ** ** ****** * *** **
*** * ** * ** * *** ** ** *** * *** ** ** *
**** ** * * * *** * ** * ** ** * * *** * * * *** * ** * && a[j]>x)
* *** * * * * ** * ****** * ****** *** * * **
** * ** * ** ** * **** ** ** * * ***** ** ** * ** ***** * * **
* * * ****** * * ** * **** * ** * * **** * **** * * * * * ** * **
* **** * * ** ***** * ** * ** * ** * *
** * * * *** * * *** *** ** *** *** ** * ** ** **

    }

}

template <class sort>

void show_items(sort a[],int n)

{
** * ** ** * * * * * * i;
* * * ** * ** *** * ***** *** ** **
******** ** * * *** ***** * ****** * * *
*** *** ** * ** ** ***** * ** * * ***** * * ** ********* ********* * **** **** *** ** **** ** ";
*** *** * **** * * * *** ** ** ******* * **** *
* ** ** ** * * * * ***** * * ** ** * * * ** ** *** ** * *** **** ***
** **** ** **** **** *

}

int main()

{
* * ** * * * *** * farr[] = {1.2,6.5,8.3,9.1,5.5,2.6,4.9,3.2,7.9};
*** * **** ***** iarr[] = {9,1,8,5,2,4,3,6,7};
** * * * ****** * * carr[]= {'a','b','d','h','g','j','c','e','f'};
* * * * * * * * ** ** sarr[]= *** *** * * * * *** * * * ****** **** * *** * * * * * * ** ** * ** * *** ****** ** *** ** ***** * **** * * * **
******** * ** ** * *** * *** ** *******
** ****** *** * *** * * << "Sorted integer array: ";
* ** ***** ** * * *** * * *** ** ***
* * * * * ***** **** ** * * ** * **
***** ** ** ** ** * * * ** *
* ***** ******* ****** << "Sorted float array: ";
* * * * *** ** *** * * * * * * **
*** * *** *** * * * ** ******* * ** * *
* * ** ***** * * * * *** *** ***
*** ******* * * *** * * << "Sorted char array: ";
** *** **** **** ** * ** * *
**** * **** * * ** ** * ** *** **** *
** **** **** **** * * * *** *
* **** *** * * * * *** ** << "Sorted string array: ";
* ** * ** ** ***** * *

}
trả lời bởi (-249 điểm)
0 thích 0 k thích
Hidden content!
#include ***** ** ** ****

#include <string.h>

using namespace std;



template <class T>

void show_items(T input[], int max_val){
* **** ** ** **** ** *** *** i;
*** **** * ** * * **** * i<max_val; i++){
******** ** **** ***** * * * ***** ** *** * << input[i];
** * * *** ** * * * * **** * *** * ****** ** ** **** ** ** * cout << " ";
* *** * *** ** * * *
* * *** * ** **** ** << endl;

}



template <class K>

void inserti_sort(K input[], int max_val){
* ***** ** ** ** i, j;
** * ** * ***** ** *** mod;
** * * **** * * * ** * ***** ** i<max_val; i++){
* * ** *** * * ** * * ****** * ** * **** j<(max_val-1); j++){
* *** * ** ** **** * ** * * * * * **** ** ** ** **** ********* *** * ****
* * ** ** * *** **** ***** * **** ** ** ** ** * * **** ** ******* * * ** * ** * * = input[j];
* ***** ** ** * ** * ***** ** **** * **** *** ** ** ** *********** ** ** ****** * * * **** *** * * * * ** = input[j+1];
* *** * ****** ** * ******* * ** * *** * ** ** * * * * ** ** * *** * *** ** **** * * * = mod;
** * *** ** ** *** * ** * ****** * ***** *** * ** **** ** ** **
* * * ** *** ***** * * * * ** * **** *** ***
***** * *** ** * * * ** **

}


* * * T>

void insert_sort(T arr[], int len) {
*** ** * ** ** * *** i, j;
* ***** ** ** ** * * temp;
* * ***** * ** * ** *** * (i = 1; i < len; i++) {
* * * ** * *** ** *** * ** * ** * = arr[i];
* ** ** * ** ** ** ** ** **** ** *** * * * = i - 1;
* *** ******* ** * * * * * * **** ** ** ** * * (; j >= 0 && arr[j] > temp; j--)
* ** * ** * ** ** * * ** * * ***** * ******* **** * ****** * ** + 1] = arr[j];
** ** ** ** * * * * **** **** * ** ** + 1] = temp;
* * ** ** * ** * * *

}



int main()

{
** **** ** **** * ** * *** farr[] = * * * * **** * *
* ** * *** *** * * * iarr[] = {9,1,8,5,2,4,3,6,7};
**** * * ** * * * *** carr[]= ** ** ** ** ** *** *** ** *
*** * ** * * *** * * ** * sarr[]= * * * * ** ** ***** * *** ** ** * * * ** * *** * * * * * * * *** ***** * ***** * ** **** * * *** ** * **** ** ** *
** ** * * * ***** * ** * * *
**** **** * * ** * * << "Sorted integer array: ";
* * * ** * * *** ** * ** * **** **
** ** ** **** * * * ** **** * **
* * ** **** * **** * * * ****
** *** * * ** *** * * *** << "Sorted float array: ";
* * * ** ** * * ** * * ** * **
*** * * * * * *** *** * * ** *
**** ** * * * ** * ***** **** *
* * * * * **** *** ** << "Sorted char array: ";
* ** * * * *** *** *** * * * **
* *** * * * *** ** * ** * * * ***
** * * * ** * * ****** * * ** * **
** * *** ** ***** ** * ** * << "Sorted string array: ";
* ** * * ******** *** * ** * ****

}



/*

string N[] = * ** ** *** * * * ** * * ** * **** *** **** * ** "six", **** * * ** *** *** * ** * * ****
** *** * * * * ******* ** *** i<max_val; i++){
* * *** * * * * **** **** * * * ** * * * * j<9; j++){
*** ** * * * * * ** * * ** **** * *** * * ** * *** * *** *** ** *** ** ** * N[j]){
***** ******** * * * * *** * * *** ** *** **** * * ***** * * **** ** * * * *** * * * * **** *
* * ** * * ** **** *** * * * * * *** * * * ** *** ** *** ** * * ** ** * ***** ***
* ** ******** * *** ********** ********* * * * * *** **** ** *** * ***** * ***
* * *** * * * * * * * ** * *** * * **
***** * * **** * *

*/
trả lời bởi (-368 điểm)
0 thích 0 k thích
Hidden content!
#include * ** * *****

#include * ** ** * *

using namespace std;


*** **** ** * T>

void swapvalue(T& value1,T& value2)

{
* * * ** ******* * * temp;
*** ***** * ** * ** **
***** * ***** **** * **
** * * * * *** ** * **

}


* ** * * * ** T>

int bubble(const T a[],int startindex,int used)

{
* ***** ** * * ** * ** * ***
* *** ***** * *** ** * * ****** * * **
** ****** *** *** ** *** ** * **** ** ***
* ** ** * * ***
* * ******** * * *** * ** * ** * ** **** * * * *
* * * ** ** * **** ** * * * *** * ****** * * ***
* * * * **** ****
******* ** ** *** ****** indexofmin;

}


*** *** T>

void show_items(T a[],int used)

{
****** *** * ** ** * (int * *** *** **
* ** ****** ** * * **** *
******* * * * ** * ** *** ***** ** * ***** * *** * * * **** ***** *** ** * * ** ** *
** * *** ** ** ** ** * *

}


* ** * * ** T>

void insert_sort(T a[],int num)

{
* ** * * * * ***** * first;
* ** ****** *** *** * * ** * ** * *** * *
* * * *** *** * * ** * **
* ** ** ** * * ** *** ** * * * * ** * * = * * ** * *
****** ***** * * * * *** *** * * * * * **** ****
** ***** *** *** *** * *



}*/
** * * * T>

void insert_sort(T arr[], int len) {
* * * * * ** * i, j;
* * ** * ** * **** * *** temp;
** * * ** * *** ** * * (i = 1; i < len; i++) {
* * * * * * * * ** * *** * ** * ** ** * * * * * = arr[i];
* ** * * ** * * * * * * * ** **** * * * = i - 1;
* **** * * * * * *** **** ** *** * ** (; j >= 0 && arr[j] > temp; j--)
* **** * * ** * ** * ** * * * ** ** ** * ***** ** *** *** ** ***** * * + 1] = arr[j];
* * * *** * ** * *** ** * * *** ** ** ** * + 1] = temp;
***** *** * * ** * * * * ** ** * * * *

}



int main()

{
** * ** * * *** farr[] = ** * * * * * * ** ** **
* *** **** * *** ** *** iarr[] = {9,1,8,5,2,4,3,6,7};
* * *** ** ** * **** **** * carr[]= *** * * * ** ***
* ****** * * ** *** sarr[]= *** * ** * * * * * *** **** * * ** * * *** * * ** * * * ** **** ** * *** *** **** * * * * **** *** * * ** ***
* * *** * ** ** ***** * *** **** **
* **** ***** ** ***** << "Sorted integer array:";
* ****** ** ******** ***
* * ** **** *** ** * * *** * ** * * *
* * * ** *** **** * *** ** ****
** * * **** ** **** << "Sorted float array:";
** * ** ** **** * * * * **** * *
** * **** * * * ** * ** *** * * ** *
* * *** * *** * *
* * *** * * * * * << "Sorted char array:";
* ** * **** * * * * * ****
* * ** ** ** ******* *** **** ** **** **
* ** *** * * *** ****** *** **
*** * ** * ** * *** ** * << "Sorted string array:";
***** ** ** * ** ** * ** * *

}
trả lời bởi (-412 điểm)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.130.18
©2016-2025

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

0 thích 0 k thích
15 trả lời
[Exercise] Coding (C) - đã hỏi ngày 1 tháng 6 năm 2017 trong C++
ID: 24854 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 3.2k đã xem
0 thích 0 k thích
22 trả lời
[Exercise] Coding (C) - đã hỏi ngày 8 tháng 6 năm 2017 trong C++
ID: 24895 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 3.9k đã xem
0 thích 0 k thích
17 trả lời
[Exercise] Coding (C) - đã hỏi ngày 1 tháng 6 năm 2017 trong C++
ID: 24855 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 3.2k đã xem
12,783 câu hỏi
183,442 trả lời
172,219 bình luận
4,824 thành viên