Results 1 to 6 of 6

Thread: How to implement the front() in C++

  1. #1
    Join Date
    Jan 2010
    Posts
    26

    How to implement the front() in C++

    Hello, I am the student of the MscIT. I have learned the C++ language in the BscIT. But I can not know about the Header file functions. So, I would like to know about the front() function. I also would like to know about how can I able to implement the front() function in the C++ program and what can be the use of the front() function in the C++ language. Can anyone help me???

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

    Re: How to implement the front() in C++

    The front() function of the C++ language can be used for an access the next an element of the queue. The front() function can returns a address to the next an element in given specified the queue. That can be the oldest an element in the given specified queue and the similar an element that can be popped out from the given queue if member of the queue that is pop can be called.

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

    Re: How to implement the front() in C++

    The front() function can be used to display a address to the first an element at the front of the given specified queue of the C++ language. The following can be the general syntax of the front() function in the C++ language as :
    Code:
    value_type& front ( );
    const value_type& front ( ) const;

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to implement the front() in C++

    The following code of lines can demonstrates you that how can you implement the front() function in the C++ language :
    Code:
    #include <iostream>
    #include <queue>
    using namespace std;
    int main ()
    {
      queue<int> mque;
      mque.push(77);
      mque.push(16);
      mque.front() -= mque.back();    
      cout << "mque.front() is now " << mque.front() << endl;
      return 0;
    }
    Output:
    Code:
    mque.front() is now 61

  5. #5
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to implement the front() in C++

    The front() function can be the member function that can an effectively calls the member with the similar name in the belonging class of an object. The front() function can returns a reference to the next element in the given specified queue. Member type value_type can be specified to the type of value that can be consisted by the underlying class, that can be the same as the first template parameter (S).

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

    Re: How to implement the front() in C++

    The front() function can produce the address to the first element of the given specified vector and that can execute in the constant time. For an example, the bellowed code that can uses a vector and the sort()_algorithm to view the first word that can be entered by a user in an alphabetical order :
    Code:
        vector<string> words;
        string str;
        while( cin >> str ) words.push_back(str);
        sort( words.begin(), words.end() );
        cout << "In alphabetical order, the first word is '" << words.front() << "'." << endl;
    When provided with this input:
    now can the time for all good men to come to the aid of their country
    …the above code displays:
    Code:
        In alphabetical order, the first word is 'aid'.

Similar Threads

  1. Replies: 3
    Last Post: 29-07-2011, 08:33 AM
  2. Implement TCP beacons
    By mrcape in forum Networking & Security
    Replies: 1
    Last Post: 21-05-2011, 03:38 AM
  3. Implement the isgraph() : C
    By Gaauge in forum Software Development
    Replies: 4
    Last Post: 09-02-2010, 05:09 PM
  4. How to implement IP Sec
    By Enriquee in forum Technology & Internet
    Replies: 5
    Last Post: 12-01-2010, 06:28 AM
  5. Front USB and lights not working on front of computer
    By Earth in forum Hardware Peripherals
    Replies: 3
    Last Post: 25-08-2009, 11:04 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,718,722,073.66388 seconds with 17 queries