functions using link lists

This is a discussion on functions using link lists within the C++ Programming forums, part of the General Programming Boards category; does anybody have any fuctions examples that add and divid using link lists. The data is past into the link ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    functions using link lists

    does anybody have any fuctions examples that add and divid using link lists. The data is past into the link list using a input file and then ouputed. I am suppose to pass the data into a class and the calculate it. my problem is trying to implement the link list into my fuction.

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    search google for link list tutorials
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    131
    Quote Originally Posted by durban
    search google for link list tutorials
    agreed....there are hundreds of them.....

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Here's an example:
    Code:
    #include <iostream>
    #include <list>
    
    using namespace std;
    
    int add(list<int>::iterator current, list<int>::iterator end)
    {
    	int sum = 0;
    	for( ; current != end; current++)
    	{
    		sum += *current;
    	}
    	return sum;
    }
    
    int addEm(list<int> aList)
    {
    	list<int>::iterator current = aList.begin();
    	list<int>::iterator end = aList.end();
    
    	int sum = 0;
    
    	for( ; current != end; current++)
    	{
    		sum += *current;
    	}
    	
    	return sum;
    }
    
    int main()
    {
    	list<int> myList;
    	myList.push_back(10);
    	myList.push_back(20);
    	myList.push_back(30);
    
    	int sum = add(myList.begin(), myList.end());
    	cout<<sum<<endl;
    
    	int sumEm = addEm(myList);
    	cout<<sumEm<<endl;
    
    	return 0;	
    }
    Last edited by 7stud; 10-31-2005 at 03:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I'm confused about link lists (again)
    By JFonseka in forum C Programming
    Replies: 4
    Last Post: 06-13-2008, 08:13 PM
  2. Replies: 4
    Last Post: 02-21-2005, 05:11 PM
  3. destructor with a link list
    By Bones in forum C++ Programming
    Replies: 1
    Last Post: 09-24-2003, 12:01 PM
  4. Attaching functions to a class/struct
    By VirtualAce in forum Tech Board
    Replies: 2
    Last Post: 08-04-2003, 10:56 AM
  5. Expression Manipulator v0.2 (bug fixes, functions)
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-26-2003, 04:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21