Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 15-03-2010
Member
 
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???
Reply With Quote
  #2  
Old 15-03-2010
Member
 
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.
Reply With Quote
  #3  
Old 15-03-2010
Member
 
Join Date: May 2008
Posts: 2,008
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;
Reply With Quote
  #4  
Old 15-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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
Reply With Quote
  #5  
Old 15-03-2010
Member
 
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).
Reply With Quote
  #6  
Old 15-03-2010
Member
 
Join Date: May 2008
Posts: 2,293
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'.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to implement the front() in C++"
Thread Thread Starter Forum Replies Last Post
ONKYO TX-SR304: Can my rear and front channels be on my front speakers Where-TO Hardware Peripherals 3 29-07-2011 08:33 AM
Implement TCP beacons mrcape Networking & Security 1 21-05-2011 03:38 AM
Implement the isgraph() : C Gaauge Software Development 4 09-02-2010 05:09 PM
How to implement IP Sec Enriquee Technology & Internet 5 12-01-2010 06:28 AM
Front USB and lights not working on front of computer Earth Hardware Peripherals 3 25-08-2009 11:04 PM


All times are GMT +5.5. The time now is 06:23 PM.