The question is : Consider an array of numeric strings where each string is a positive number with anywhere from 1 to 10^6 digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array.
vector<string> bigSorting(vector<string> unsorted) {
for(int i=0 ; i<unsorted.size() ; i++){
for(int j=0 ; j<unsorted.size()-1; j++){
long int a = stol(unsorted[j]);
long int b = stol(unsorted[j+1]);
if(a > b){
string x = unsorted[j];
unsorted[j] = unsorted[j+1];
unsorted[j+1] = x;
}
}
}
return unsorted;
}
I made the above function for the question and it gave an error :
terminate called after throwing an instance of 'std::out_of_range'
what(): stol
Reading symbols from Solution...done.
[New LWP 450]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./Solution'.
Program terminated with signal SIGABRT, Aborted.
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
To enable execution of this file add
add-auto-load-safe-path /usr/local/lib64/libstdc++.so.6.0.25-gdb.py
line to your configuration file "//.gdbinit".
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "//.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
info "(gdb)Auto-loading safe path"
What is the meaning of this error code and how do I fix it?