[C++] Sort the digits | Cleaar and Concise Solution with Comments
Hint-1: For positive numbers, the leading digit should be the smallest nonzero digit. Then the remaining digits follow in ascending order.\nHint-2: For negative
**Hint-1:** For positive numbers, the leading digit should be the smallest nonzero digit. Then the remaining digits follow in ascending order.\n**Hint-2:** For negative numbers, the digits should be arranged in descending order.\n\n```\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        long long ans = 0, orignalnum = num;\n        vector<int> nums;\n        while(num != 0){\n                nums.push_back(num % 10);\n                num /= 10;\n        }\n        sort(nums.begin(), nums.end()); // store the given no. in vector and sort it\n        \n        if(orignalnum > 0){\n            int zeros = 0;\n            for(int i = 0; i < nums.size(); i++){\n                if(nums[i] == 0) \n                    zeros++;  // count no. of zeros\n                else{\n                    ans = ans * 10 + nums[i];\n        // place all zeros in ans once you find first non-zero element so that ans does not contain any leading zeros.\n                    while(zeros > 0) zeros--, ans *= 10;\n                }\n            }\n        } else {\n            // In negative case, simply sort and put it in ans because of -ve sign vector will automatically be sorted in descending order \n            for(int i = 0; i < nums.size(); i++)\n                    ans = ans * 10 + nums[i];\n        }\n        return ans;\n    }\n};\n// Dry Run Code with given examples  for better Understanding\n```
['C', 'Sorting', 'C++']