Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- void swap(int &a, int &b){
- int c;
- c=a;
- a=b;
- b=c;
- }
- void bob(int mas[],int n){
- bool exit = false;
- while (!exit){
- exit=true;
- for(int i=0;i<n-1;i++){
- if(mas[i]>mas[i+1]){
- swap(mas[i],mas[i+1]);
- exit=false;
- }
- }
- }
- }
- void n_bob(int mas[],int n){
- bool exit = false;
- while (!exit){
- exit=true;
- for(int i=0;i<n-1;i++){
- if(mas[i]<mas[i+1]){
- swap(mas[i],mas[i+1]);
- exit=false;
- }
- }
- }
- }
- int main(){
- char* str = new char;
- cin>>str;
- string ss(str);
- int* a = new int[ss.length()];
- for(int i = 0; i<ss.length();i++){
- char t;
- t=ss[i];
- a[i]=t-'0';
- }
- for(int i =0;i<ss.length();i++){
- //cout << a[i] << ' ';
- }
- //cout<<"\n";
- bob(a,ss.length());
- for(int i =0;i<ss.length();i++){
- cout << a[i];
- }
- cout<< ' ' ;
- n_bob(a,ss.length());
- for(int i =0;i<ss.length();i++){
- cout << a[i];
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement