本文整理汇总了C++中forward_list::empty方法的典型用法代码示例。如果您正苦于以下问题:C++ forward_list::empty方法的具体用法?C++ forward_list::empty怎么用?C++ forward_list::empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forward_list
的用法示例。
在下文中一共展示了forward_list::empty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: insertString
void insertString(forward_list<string> &strflst, const string &search, const string &str)
{
auto prev = strflst.before_begin();
auto curr = strflst.begin();
if (!strflst.empty())
{
bool flag = false;
while(curr != strflst.end())
{
if (*curr == search)
{
curr = strflst.insert_after(curr, str);
flag = true;
}
else
{
prev = curr++;
}
}
if (!flag)
{
strflst.insert_after(prev, str);
}
}
}
示例4: 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;
}
示例5: printList
template <typename T> void printList(const forward_list<T> &listRef)
{
if (listRef.empty())
cout<<"List is empty";
else
{
ostream_iterator<T> output(cout, " ");
copy(listRef.begin(), listRef.end(), output);
}
}
示例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){
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
}
}
示例8: 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
示例9: 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;
}
示例10: 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);
}
}