diff --git a/Sorting names in an alphabetical order.cpp b/Sorting names in an alphabetical order.cpp new file mode 100644 index 0000000..eaa5384 --- /dev/null +++ b/Sorting names in an alphabetical order.cpp @@ -0,0 +1,55 @@ +#include +using namespace std; + +//function to print the array +void print(vector names){ + printf("printing ........\n"); + for(int i=0;i alphabaticallySort(vector a){ + int n=a.size(); + //mycomp function is the defined function which + //sorts the strings in alphabatical order + sort(a.begin(),a.end(),mycomp); + return a; +} + +int main() +{ + int n; + printf("enter number of names to be added: "); + scanf("%d",&n); + + //creating a vector of strings + //vector to store strings(names) + vector names; + string name; + printf("enter names: \n"); + //taking input + for(int i=0;i>name; + //insert names into the vector + names.push_back(name); + } + + printf("\nbefore sorting\n"); + print(names); + + //function to sort names alphabetically + names=alphabaticallySort(names); + + printf("after alphabetical sorting\n"); + print(names); + + return 0; +}