Linked List with a node using push_back

I am having trouble with void push_back() i dont knwo what to put in the () to make it work.



#include <iostream>

#include <fstream>

#include <vector>

#include <iterator> //googled these systemss from here on down

#include <stdio.h>

#include <stdlib.h>

using namespace std;



class Line {



public:


Line();

Line(string c);

string get_line() const;

void set_line(string c);



private:



string line;


};



Line::Line()



: line("") {}



Line::Line(string c)



: line(c) {}


string Line::get_line() const {

return line;
}



void Line::set_line(string c){

line = c;
}

//Linked List is a list of nodes so this class is neccessary.


class Node {



public:



Node(Line n);


Line get_pro();



private:



Node *next;

Line pro;


friend class TiedList; // this is what access and stores the nodes
};



Line Node::get_pro(){



return pro;

}




class TiedList {



public:


TiedList();

TiedList(const TiedList & first);

~TiedList();


TiedList &operator=(const TiedList &second);


bool empty() const;

int length() const;


Node get(int collection);


void push_front(Line pro);


void pop_front();

void push_back();

void remove(int ps);

void insert(string line_in,int ps);



private:



Node *copy_node(const Node *in) const;


Node *first;

};


Node::Node(Line n)


: next(NULL), pro(n) {}

//Creates an empty list.



TiedList::TiedList() {



first = NULL;

}



bool TiedList::empty() const {



if (first == NULL) {



return true;

}


else


return false;

}




int TiedList::length() const {



int l = 0;


for(Node *car = first; car != NULL; car = car->next) {



l++;


}



return l;


}


Node TiedList::get(int collection) {



Node* car = first;


for(int l=0; l < collection; l++) {



car = car->next;



return Node(Line(""));


}



if(car == NULL) {



return Node(Line(""));



}



else



return *car;

}



Last edited on
http://www.cplusplus.com/reference/list/list/push_back/

push_back() adds a new element to the end of the list. You are going to need to pass the node you would like to pin to the back of the list.
put your code in proper format
Topic archived. No new replies allowed.