Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- using namespace std;
- void sort(int arr[], int a){
- for (int i = 0;i < a; i++){
- for (int j = 1; j <= a - 1; j++){
- if (arr[j] < arr[j-1])
- swap(arr[j], arr[j-1]);
- }
- }
- }
- void SortNumbers(string &src){
- string temp = "", new_str = "";
- int t = src.size();
- int k = 0;
- int temp_ = 0;
- int arr[15];
- for(int i = 0; i < t;i++){
- if(src[i] != ' '){
- temp += src[i];
- }
- else
- {
- if(atoi(temp.c_str()) != 0){
- temp_ = atoi(temp.c_str());
- arr[k] = temp_;
- temp = "";
- k++;
- }
- else
- temp = "";
- }
- }
- temp = "";
- sort(arr, k);
- int c = 0;
- for(int i = 0; i < t; i++){
- if(src[i] != ' '){
- temp += src[i];
- }
- else
- {
- if(atoi(temp.c_str()) != 0){
- new_str += to_string(arr[c]);
- c++;
- new_str += " ";
- temp = "";
- }
- else{
- new_str += temp;
- new_str += " ";
- temp = "";
- }
- }
- }
- cout << new_str << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement