Results 1 to 6 of 6

Thread: Assistance to implement the unique() in coding of the C++

  1. #1
    Join Date
    Jan 2010
    Posts
    19

    Assistance to implement the unique() in coding of the C++

    Hello, I am the student of the Bsc-CS. I have to submit the Project on the functions of the C++ language in three days. I can have the well knowledge of the functions that can be used in the C++ language. Even if, I can not know much more about the unique() function of the C++ language. So, I want to know about the unique() function of the C++ language. I also want assistance for to implement the unique() function in the C++ Coding. Reply Me!!

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    The unique() in coding of the C++

    Hello, According to me the unique() function can be used in the C++ language to remove the consecutive duplications that can be available in the range. The behavior of the unique() function template can be similar to the following as :
    Code:
    template <class FrwrdItrtr>
      FrwrdItrtr unique ( FrwrdItrtr fst, FrwrdItrtr lst )
    {
      FrwrdItrtr rslt=fst;
      while (++fst != lst)
      {
        if (!(*rslt == *fst))  
          *(++rslt)=*fst;
      }
      return ++rslt;
    }

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Implement the unique() in coding of the C++

    I suggest you to go through the following program step by step to understand easily and that can helpful for you to gather the knowledge of the unique() function in the C++ coding :
    Code:
    #include <iostream>
    #include <algoritrhm>
    #include <vector>
    using namespace std;
    bool mfnctn (int i, int j)
     {
      return (i==j);
    }
    int main () 
    {
      int mit[] = {10,20,20,20,30,30,20,20,10};   
      vector<int> mvctor (mit,mit+9);
      vector<int>::itrerator itr;
      itr = unique (mvctor.begin(), mvctor.end());
      mvctor.resize( itr - mvctor.begin() );       
      unique (mvctor.begin(), mvctor.end(), mfnctn); 
      cout << "mvctor contains:";
      for (itr=mvctor.begin(); itr!=mvctor.end(); ++itr)
        cout << " " << *itr;
      cout << endl;
      return 0;
    }
    Output:
    Code:
    mvctor contains: 10 20 30 20 10

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    The unique() in coding of the C++

    The following can be the parameters of the unique function in the C++ language :
    1. prd : This parameter can be used in the C++ language for the binary predicate that can taking two elements as argument and can returns the result of the comparison between both of them.
    2. fst, lst : these parameters can be used in the C++ language for the forward iterators to the final and starting positions of the given specified sequence. The range used can be as[fst,lst).

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    The unique()

    The unique() function can be used to remove the consecutive duplicates of an element in the given specified range. The following can be the general syntax of the unique() function can be as :
    Code:
    template <class FrwrdItrtr>
      FrwrdItrtr unique ( FrwrdItrtr fst, FrwrdItrtr lst );

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: Assistance to implement the unique() in coding of the C++

    The unique() function can be used to remove the consecutive duplicates in the range. If the binary predicate variable can be given, then it can be used to check the two elements to determine whether they can be duplicated or not. The unique() function can returns an iterator to the end of the range that can be modified. The unique() function can runs in the linear time. I guess this information can works for you, if not then reply me.

Similar Threads

  1. How to use the pop_heap() in C++ coding
    By Garrick in forum Software Development
    Replies: 4
    Last Post: 05-03-2010, 05:28 PM
  2. Help me to use the transform() in C++ coding
    By Tailor in forum Software Development
    Replies: 5
    Last Post: 19-02-2010, 04:17 PM
  3. Help in coding documents
    By Remedy in forum Software Development
    Replies: 5
    Last Post: 11-02-2010, 02:34 AM
  4. C++ coding faster?
    By Chandrakant81 in forum Software Development
    Replies: 3
    Last Post: 17-02-2009, 10:51 PM
  5. Problem with C coding
    By SANDESH49 in forum Software Development
    Replies: 2
    Last Post: 02-09-2008, 01:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,513,228.40795 seconds with 16 queries