当前位置: 首页>>代码示例>>C++>>正文


C++ forward_list类代码示例

本文整理汇总了C++中forward_list的典型用法代码示例。如果您正苦于以下问题:C++ forward_list类的具体用法?C++ forward_list怎么用?C++ forward_list使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了forward_list类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的forward_list类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。