✔ C++ || Sorting Digits
Connect with me Linkedin\n\n long long smallestNumber(long long num) {\n        \n        \n        \n        vector<int> digits;\n        \n        if(num==0) 
**Connect with me** [Linkedin](https://www.linkedin.com/in/sarvesh-khandelwal-206b171a7/)\n```\n long long smallestNumber(long long num) {\n        \n        \n        \n        vector<int> digits;\n        \n        if(num==0) return 0;\n        if(num<0){\n            num*=-1;\n            \n            \n            while(num){\n                digits.push_back(num%10);\n                num/=10;\n            }\n            \n            \n            \n            sort(digits.begin(),digits.end(),greater<int>());\n            long long ans=0;\n            \n            for(int i=0;i<digits.size();i++){\n                ans=ans*10 + digits[i];\n            }\n            \n            \n            return -1*ans;\n        }\n        else{\n            \n            \n            \n            while(num){\n                digits.push_back(num%10);\n                num/=10;\n            }\n            \n            \n            long long ans=0;\n            sort(digits.begin(),digits.end());\n            \n            \n            for(auto x: digits) cout<<x<<" ";\n            cout<<endl;\n            int zero=0;\n            \n            \n            int i=0;\n            \n            while(digits[i]==0) {\n                zero+=1;\n                i+=1;\n            }\n            \n            ans=digits[i];\n            \n            \n            while(zero--){\n                ans=ans*10 + 0;\n            }\n            for(int j=i+1;j<digits.size();j++){\n                ans=ans*10 + digits[j];\n            }\n            \n            \n            return ans;\n        }\n    }\n```
['C', 'C++']