Ok So I'm studying linked list and pointers and having some fun with it. I have tried some different read and print methods using pointers. I can't get it to compile. I started to re write the program and compile it every time once I write a new method or function.
the problem is "pointer.cc:57:16: error: cannot convert ‘element* {aka int*}’ to ‘listnode*’ in assignment"
#include <iostream>
#include <stdlib.h>
#include <limits>
#include <string>
usingnamespace std;
# undef NULL
typedefint element;
constint NULL=0;
constint SENTINEL=-1;
class listnode{
public:
element data;
element * next;
};
class LList{
private:
listnode * head;
listnode * tail;
public:
LList(); //Constructor
~LList(); //Destructor
void Read();
void Readforward();
void Readbackward();
void Print();
void Clean();
};
int main(){
LList L;
L.Readforward();
L.Print();
}
LList::LList(){
//PRE: None
//POST: The N.O. is valid
head=NULL;
}
LList::~LList(){
//PRE: The N.O. is valid
//POST: The N.O. is valid and empty and all borrowed system resources
// have been given back
Clean();
}
void LList::Clean(){
//PRE: The N.O. LList is valid
//POST: The N.O. is no empty, and all of it's previous listnodes
// have been given to the system memory pool ("heap")
listnode * temp;
while(head != NULL){
temp= head;
head= head -> next;
delete temp;
}
}