本文整理汇总了C++中forward_list::front方法的典型用法代码示例。如果您正苦于以下问题:C++ forward_list::front方法的具体用法?C++ forward_list::front怎么用?C++ forward_list::front使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forward_list
的用法示例。
在下文中一共展示了forward_list::front方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: primeCount
int primeCount(forward_list<int> lst){
if(lst.empty()){ //base case
return 0; //empty list has no (prime) numbers
}
if(isPrime(lst.front())){ //check if first item is prime
cout << lst.front() << endl;
lst.pop_front(); //can do this bc lst is passed by value
return 1 + primeCount(lst); //recursive call
}
else{ //first number isnt prime
lst.pop_front(); //dont output, just delete it
return primeCount(lst); //dont add 1 to primecount
}
}
示例2: printLots
void printLots(forward_list<T> L, forward_list<int> P){
int temp = 0;
while(!P.empty()){
int pos = P.front() - temp;
temp = pos;
for(; pos > 0; --pos){
L.pop_front();
}
cout << L.front() << " ";
P.pop_front();
}
//keep L.pop_front() until you get to the right position
return;
}
示例3: printLots
void printLots(forward_list<T> L, forward_list<int> P)
{
int num_elem = 0;
for (typename forward_list<T>::iterator count = L.begin() ; count != L.end() ; ++count)
{
num_elem = num_elem + 1;
}
while(!P.empty())
{
int pos = P.front();
if(pos >= num_elem)
{
cout << "Position out of bounds!" << endl;
return;
}
typename forward_list<T>::iterator start = L.begin();
for(int i = 0 ; i < pos ; i++)
{
++start;
}
cout << *start << ", ";
P.pop_front();
}
cout << endl;
}
示例4: primeCount
int primeCount(forward_list<int> lst)
{
int total;
if(lst.empty())
{
return 0;
}
else
{
bool prime = isPrime(lst.front());
lst.pop_front();
if(prime == true)
{
total = 1 + primeCount(lst);
}
if(prime == false)
{
total = primeCount(lst);
}
}
return total;
}
示例5: listCopy
forward_list<T> listCopy(forward_list<T> L, forward_list<T> &P){
//concatenate L - in reverse - to the back of P
forward_list<T> temp;
while(!L.empty()){
temp.push_front(L.front());
L.pop_front();
}
P.reverse();
while(!P.empty()){
temp.push_front(P.front());
P.pop_front();
}
P = temp;
return P;
}
示例6: primeCount
int primeCount(forward_list<int> lst){
if(lst.empty()){
return 0;
}else{
bool prime = isPrime(lst.front());
lst.pop_front();
if(prime){
return 1 + primeCount(lst);
}else{
return primeCount(lst);
}
}
}
示例7: primeCount
int primeCount( forward_list<int> lst ){
static int counter = 0;
if( lst.empty() ) { return 0; }// If lst is empty, then counter = 0.
else
{
if ( isPrime( lst.front() ) ){ ++counter;}
}
lst.pop_front();
primeCount(lst);
return counter;
} // Function that returns number of Primes in a forward_list
示例8: primeCount
int primeCount(forward_list<int> lst)
{
if(lst.empty()) //If list's size is 0, return 0;
{
return 0;
}
else if(isPrime(lst.front())) //If the number is prime, pop the front, add one, call the function again.
{
lst.pop_front();
return 1 + primeCount(lst);
}
else //If it isn't prime, pop the front and call the function again.
{
lst.pop_front();
return primeCount(lst);
}
}
示例9: find_last_kth
T find_last_kth(const forward_list<T>& l, int k)
{
assert(k>=0);
auto it = l.begin();
for (int i=0; i<k; ++i) {
if (it==l.end()) {
return l.front();
}
++it;
}
auto ret = l.begin();
while (it!=l.end()) {
++it;
++ret;
}
return *ret;
}
示例10: playSound
sf::Sound& playSound(const string& filename, Vec2 pos) {
sounds.emplace_front(loadSoundBuffer(filename));
sf::Sound& sound = sounds.front();
sound.setPosition(pos.x, pos.y, 0);
sound.setAttenuation(0.005);
sound.play();
return sound;
}