POV-Ray : Newsgroups : povray.off-topic : Reflections on employment : Re: Reflections on employment Server Time
28 Jul 2024 20:22:03 EDT (-0400)
  Re: Reflections on employment  
From: Warp
Date: 2 Dec 2012 11:21:40
Message: <50bb8014@news.povray.org>
Orchid Win7 v1 <voi### [at] devnull> wrote:
> Haskell:

>    foobar :: String -> [Int]
>    foobar = sort . map read . words


> C#:

>    public List<Int> foobar(String s)
>    {
>      string[] words = s.Split(' ');
>      List<Int> list = new List<Int>();
>      foreach (String word in words) {list.add(int.Parse(word));}
>      list.Sort();
>      return list;
>    }

In C++ I would probably write it like:

    std::vector<int> foobar(const std::string& s)
    {
        std::istringstream is(s);
        std::vector<int> result;
        int value;
        while(is >> value) result.push_back(value);
        std::sort(result.begin(), result.end());
        return result;
    }

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.