From 19ec8144e8de1bee68731e2509190d1cb87e8d44 Mon Sep 17 00:00:00 2001 From: HIMANSHU SHARMA Date: Sun, 27 Oct 2019 11:59:06 +0530 Subject: [PATCH] cpp-generic-sort.cpp You need to sort elements of an array where the array can be of following data-types: Integer String floating numbe Your task is to complete the given two functions: sortArray() and printArray() --- sorting-algorithms/cpp-generic-sort.cpp | 66 +++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 sorting-algorithms/cpp-generic-sort.cpp diff --git a/sorting-algorithms/cpp-generic-sort.cpp b/sorting-algorithms/cpp-generic-sort.cpp new file mode 100644 index 0000000..4b254d6 --- /dev/null +++ b/sorting-algorithms/cpp-generic-sort.cpp @@ -0,0 +1,66 @@ +int main() +{ + int t; + cin>>t; + while(t--) + { + int n, q, i; + cin>>n>>q; + int intArr[n]; + string strArr[n]; + float floatArr[n]; + switch(q) + { + case 1: + for(i=0; i>intArr[i]; + } + sortArray(intArr, n); + printArray(intArr, n); + break; + case 2: + for(i=0; i>strArr[i]; + } + sortArray(strArr, n); + printArray(strArr, n); + break; + case 3: + for(i=0; i>floatArr[i]; + } + sortArray(floatArr, n); + printArray(floatArr, n); + break; + } + } +return 0; +} +template +void sortArray(T a[], int n) +{ + T c; + for(int i=0;ia[j+1]) + { + c=a[j]; + a[j]=a[j+1]; + a[j+1]=c; + } + } + } +} +template +void printArray(T a[], int n) +{ + for(int i=0;i