本文整理汇总了C++中forward_list类的典型用法代码示例。如果您正苦于以下问题:C++ forward_list类的具体用法?C++ forward_list怎么用?C++ forward_list使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了forward_list类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: while
forward_list<int> LinkedListsExpert::partition(forward_list<int> list, int x){
forward_list<int> lessThanX, greaterThanX, equalX;
forward_list<int>::iterator it = list.begin();
while (it!=list.end()) {
if (*it < x) {
lessThanX.push_front(*it);
} else if (*it > x){
greaterThanX.push_front(*it);
} else{
equalX.push_front(*it);
}
it++;
}
//merge lists
it = equalX.begin();
while (it != equalX.end()) {
greaterThanX.push_front(*it);
it++;
}
it = lessThanX.begin();
while (it != lessThanX.end()) {
greaterThanX.push_front(*it);
it++;
}
return greaterThanX;
}
开发者ID:HebaWaly,项目名称:ProblemsSolver,代码行数:26,代码来源:LinkedListsExpert.cpp
示例2: printList
void LinkedListsExpert::printList(forward_list<int> list){
std::forward_list<int>::iterator it;
for (it = list.begin(); it != list.end(); it++) {
cout << *it << " ";
}
cout << "\n";
}
开发者ID:HebaWaly,项目名称:ProblemsSolver,代码行数:7,代码来源:LinkedListsExpert.cpp
示例3: 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;
}
开发者ID:achen067,项目名称:CS14-SPRING2015,代码行数:27,代码来源:lab2.cpp
示例4: listCopy
void listCopy(forward_list<T> L, forward_list<T> &P) // reverse L and put it into P
{
for(typename forward_list<T>::iterator start = L.begin() ; start != L.end() ; ++start)
{
P.push_front(*start);
}
}
开发者ID:achen067,项目名称:CS14-SPRING2015,代码行数:7,代码来源:lab2.cpp
示例5: display
void display(forward_list<T> lst)
{
for(typename forward_list<T>::iterator start = lst.begin(); start != lst.end() ; ++start)
{
cout << *start << " ";
}
cout << endl;
}
开发者ID:achen067,项目名称:CS14-SPRING2015,代码行数:10,代码来源:lab2.cpp
示例6: 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);
}
}
开发者ID:CCJY,项目名称:coliru,代码行数:10,代码来源:main.cpp
示例7: remove_evens_and_double_odds
void remove_evens_and_double_odds(forward_list<int>& data) {
for (auto cur = data.begin(), prev = data.before_begin(); cur != data.end(); ) {
if (*cur & 0x1)
cur = data.insert_after(prev, *cur),
advance(prev, 2),
advance(cur, 2);
else
cur = data.erase_after(prev);
}
}
开发者ID:RanchoCooper,项目名称:Cpp-Primer,代码行数:10,代码来源:ex09_31_2.cpp
示例8: insertWord
void insertWord(forward_list<string> &forList,
const string &str1,const string &str2)
{
auto prev = forList.before_begin();
for(auto i=forList.begin();i != forList.end();prev=i,++i)
if(*i == str1){
forList.insert_after(i,str2);
return ;
}
forList.insert_after(prev,str2);
}
开发者ID:devilchew,项目名称:Exercise,代码行数:11,代码来源:练习9-28.cpp
示例9: 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);
}
}
}
开发者ID:psmit011,项目名称:CS14-SPRING2015,代码行数:13,代码来源:lab2.cpp
示例10: find_and_insert
void find_and_insert(forward_list<string> &list, string const& to_find, string const& to_add)
{
auto prev = list.before_begin();
for (auto curr = list.begin(); curr != list.end(); prev = curr++)
{
if (*curr == to_find)
{
list.insert_after(curr, to_add);
return;
}
}
list.insert_after(prev, to_add);
}
开发者ID:jimingye,项目名称:Cpp-practice,代码行数:13,代码来源:9_28.cpp
示例11: merge
// Merge a connected compontent of lines to a new line with width.
void merge(const forward_list<LineSeg*>& component, LineSegW& out) {
// TODO: in principle no loop/collection is necessary
// Note: profiling indicates this is not even close to a bottleneck, so ok for now
forward_list<Point*> component2i;
for (auto vec = component.begin(); vec != component.end(); ++vec) {
component2i.push_front(&(*vec)->s);
component2i.push_front(&(*vec)->e);
//component2i.push_front((Vec2i*)&(*vec)->val[0]);
//component2i.push_front((Vec2i*)&(*vec)->val[2]);
}
line_fit(component2i, out);
}
开发者ID:golmman,项目名称:plancv,代码行数:14,代码来源:connectlines.cpp
示例12: 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
开发者ID:Herrari,项目名称:CS14-SPRING2015,代码行数:14,代码来源:lab2.cpp
示例13: func
void func(forward_list<string> &flist, const string s1, const string s2)
{
auto before = flist.before_begin();
auto curr = flist.begin();
while(curr!=flist.end()) {
if(*curr == s1){
flist.insert_after(curr, s2);
return;
}else{
curr++;
}
}
flist.insert_after(curr, s2);
}
开发者ID:goodyang,项目名称:forlearn,代码行数:14,代码来源:exercise9.28.cpp
示例14: 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
}
}
开发者ID:bdizo001,项目名称:CS14-SPRING2015,代码行数:14,代码来源:lab2.cpp
示例15: Insert
void Insert(forward_list<string> &lst, const string &str1, const string &str2) {
auto prev = lst.cbefore_begin();
auto curr = lst.cbegin();
while (curr != lst.cend()) {
if (*curr != str1) {
prev = curr;
++curr;
}
else {
lst.insert_after(curr, str2);
return;
}
}
lst.insert_after(prev, str2);
}
开发者ID:qhx1993,项目名称:Cpp-Primer-5thEdition,代码行数:15,代码来源:ex9_28.cpp
示例16: 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;
}
开发者ID:bdizo001,项目名称:CS14-SPRING2015,代码行数:15,代码来源:lab2.cpp
示例17: ajouterPions
bool Case::ajouterPions(forward_list<Pion*> fl, int nbPionsToAdd) {
if(nbPions + nbPionsToAdd > nbPionsMax) {
cout << "[Case.cpp/ajouterPions] Erreur : Impossible de rajouter les pions. Pas assez de place." << endl;
return false;
}
else {
listePions.splice_after(listePions.before_begin(), fl);
nbPions += nbPionsToAdd;
for(auto it=fl.begin() ; it!=fl.end() ; ++it)
(*it)->setPosition(position);
return true;
}
}
开发者ID:Walcott093,项目名称:C-,代码行数:15,代码来源:Case.cpp
示例18: copieListe
void copieListe(forward_list<TypeInfo> maListeOriginale, forward_list<TypeInfo>& maListecopiee) {
// pour conserver l'ordre dans la copie il faut :
// 1 empiler les valeurs de la liste originale en faisant cun parcours complet gauche droite de la liste
// 2 dépiler les valeurs de la liste originale en les insérant en tête de la copie
// on peut au choix utiliser la ListeChaineePile déjà définie, une liste chainée en avant de la STL, ou une pile de la STL
// AVEC UNE LISTE de la STL
forward_list<TypeInfo> maCopieInversee;
// étape 1
for (TypeInfo& val : maListeOriginale) {
maCopieInversee.push_front(val);
} // end for
// étape 2
for (TypeInfo& val : maCopieInversee) {
maListecopiee.push_front(val);
} // end for
/*
// AVEC UNE PILE de la STL
stack<TypeInfo> maPile;
// étape 1
for (TypeInfo& val : maListeOriginale) {
maPile.push(val);
} // end for
// étape 2
while (!maPile.empty()) {
maListecopiee.push_front(maPile.top());
maPile.pop();
} // end while
*/
}
开发者ID:Ivan-Roger,项目名称:TP_de_Cpp,代码行数:31,代码来源:premiercontact.cpp
示例19: primeCount
inline int primeCount(forward_list<int> lst)
{
forward_list<int>::iterator itr = lst.begin(); //starts iterator at beg
int total = primeCount(lst, itr); //calls recursive helper function
return total; //returns total # of primes
}
开发者ID:tmoor008,项目名称:CS14-SPRING15,代码行数:8,代码来源:lab2.cpp
示例20: getNthToLast
int LinkedListsExpert::getNthToLast(forward_list<int> list, int n){
forward_list<int>::iterator current = list.begin();
forward_list<int>::iterator previous = list.begin();
for(int i=1; i<=n; i++){
if (current != list.end()) {
current++;
}
}
while (current != list.end()) {
current++;
previous++;
}
return *previous;
}
开发者ID:HebaWaly,项目名称:ProblemsSolver,代码行数:17,代码来源:LinkedListsExpert.cpp
注:本文中的forward_list类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论