radu.cruceru
BAN USERNot exactly right. If you pop one element which also happens to be minimum, then calling min() would give you a wrong answer. Imagine this stack:s = 7 | 8 | 3. s.min() returns 3. s.pop(); s.min() should return 7.
To achieve this, you keep the track of min (or max) in the node structure. That will give you this: s[7].min = 7 (the min when 7 is pushed), s[8].min = 7 (min when 8 is pushed), s[3].min = 3 (min when 3 is pushed.
I don't know a lot of C/C++, but what does T(11) in the very last return statement means? I don't think that should be there.
- radu.cruceru February 26, 2012I don't know a lot of C, but what does T(11) in the very last return statement means? I don't think that should be there.
- radu.cruceru February 26, 2012You can traverse them recursively and calculate the sum when you're coming back.
- radu.cruceru February 26, 2012int k=arr.size(),int one=0,int zero=0;
for(int i=0;i<k;i++)
{
if(arr[i]) one++;
else zero++;
}
i=0;
while(zero){
arr[i]=0;
i++;
zero--;
}
while(one)
{
arr[i]=1;
i++;
one--;
}
and that's it. it's a basic counting sort.
There may be 95 printable characters, but when casting c to int, what matters is the ascii code. For A is 97 so your array will be of no use.
- radu.cruceru January 12, 2013