linked list implementation

I made linked list and it needs to call these functions and implement the list. It compiles, but crashes when I run it. Any solutions?

#include <iostream>
#include "List.h"
#include<fstream>
using namespace std;
int r;
int x;


struct Node{

int data;
Node *next;
Node *prev;


};

struct HeadNode{
int counter;
Node *headPtr;
};
struct currentNode{
int ranker;
Node *currentPtr;
};

class List{
public:
List();

int sizex( );
int currentValue( );
int currentRank( );
void gotoFirst( );
void gotoLast( );
void retreat( );
void advance( );
void gotoRank (int r);
bool isNull( );
bool isFirst( );
bool isLast( );
void insertFirst (int x);
void insertLast (int x);
void insertBefore (int x);
void insertAfter (int x);
void replacex (int x);
int removeFirst( );
int removeLast( );
int removex( );
int removeAndRetreat( );
int removeAndAdvance( );
void display( );


HeadNode head;
currentNode current;

};
//List.h Stuff ^


List::List(){
head.counter = 0;
head.headPtr = NULL;
current.ranker = head.counter;
current.currentPtr = head.headPtr;
return;

}

int List::sizex(){

return head.counter;
}
int List::currentValue( ){
int x;
x = current.currentPtr -> data;
return x;
}
int List::currentRank( ){
return current.ranker;
}
void List::gotoFirst( ){
current.currentPtr = head.headPtr;
current.ranker = 1;
}
void List::gotoLast( ){
current.ranker = head.counter;
}
void List::retreat( ){
current.currentPtr -> prev = current.currentPtr;
}
void List::advance( ){
current.currentPtr -> next = current.currentPtr;
}
void List::gotoRank (int r){
current.ranker = r;
}
bool List::isNull( ){
if(current.currentPtr == NULL) return true;
else return false;
}
bool List::isFirst( ){
if(current.ranker == 0) return true;
else return false;
}
bool List::isLast( ){
if(current.ranker == head.counter) return true;
else return false;
}
void List::insertFirst (int x){
Node *ptrNew = new Node;
ptrNew -> data = x;
ptrNew -> next = head.headPtr;
head.headPtr = ptrNew;
head.counter++;
current.ranker = 1;
}
void List::insertLast (int x){
;
}
void List::insertBefore (int x) {
Node *ptrNew = new Node;
ptrNew -> data = x;
ptrNew -> prev = current.currentPtr;
current.currentPtr = ptrNew;
head.counter++;
}
void List::insertAfter (int x){
Node *ptrNew = new Node;
ptrNew -> data = x;
ptrNew -> next = current.currentPtr;
current.currentPtr = ptrNew;
head.counter++;
}
void List::replacex (int x){

current.currentPtr -> data = x;

}
int List::removeFirst( ){

bool exit;
Node *tempNode;

if ( head.headPtr )
{
tempNode = head.headPtr;
head.headPtr = head.headPtr -> next;
delete tempNode;
head.counter--;
exit = true; // returns true if successful
}
else
exit = false; // returns false if unsuccessful

return exit;
}
int List::removeLast( ){
int x;
x = current.currentPtr-> data;
return x;
}
int List::removex (){
Node *tempNode;
int x;
tempNode = current.currentPtr;
x = current.currentPtr -> data;
tempNode -> data = x;
current.currentPtr = current.currentPtr -> next;
delete tempNode;
head.counter--;
return x;
}
int List::removeAndRetreat( ){
Node *tempNode;
int x;
tempNode = current.currentPtr;
x = current.currentPtr -> data;
tempNode -> data = x;
current.currentPtr = current.currentPtr -> prev;
delete tempNode;
head.counter--;
return x;
}
int List::removeAndAdvance( ){
Node *tempNode;
int x;
tempNode = current.currentPtr;
x = current.currentPtr -> data;
tempNode -> data = x;
current.currentPtr = current.currentPtr -> next;
current.currentPtr = current.currentPtr -> next;
delete tempNode;
head.counter--;
return x;
}
void List::display(){
Node *ptr = head.headPtr;
int nodeCounter = 1;
std::cout << "\n";
std::cout << "[";
while ( nodeCounter < head.counter )
{

std::cout << " ";
std::cout << ptr -> data;
nodeCounter++;
ptr = ptr -> next;
}
std::cout << "]";
return;
}

int main(){

List list;
std::string action;
ifstream myfile;
myfile.open("Input.txt");

if (myfile.is_open()){
while(myfile.good()){
myfile >> action;

if(action.compare("size")==0){list.sizex();}
else if(action.compare("currentValue")==0) list.currentValue();
else if(action.compare("currentRank")==0) list.currentRank();
else if(action.compare("gotoFirst")==0) list.gotoFirst();

else if(action.compare("gotoLast")==0) list.gotoLast();

else if(action.compare("retreat")==0) list.retreat();

else if(action.compare("advance")==0) list.advance();

else if(action.compare("gotoRank")==0){ myfile >> r; list.gotoRank(r);}

else if(action.compare("isNull")==0) list.isNull();

else if(action.compare("isFirst")==0) list.isFirst();

else if(action.compare("isLast")==0) list.isLast();

else if(action.compare("insertFirst")==0){ myfile >> x; list.insertFirst(x);}

else if(action.compare("insertLast")==0){ myfile >> x; list.insertLast(x);}

else if(action.compare("insertBefore")==0){ myfile >> x; list.insertBefore(x);}

else if(action.compare("insertAfter")==0){ myfile >> x; list.insertAfter(x);}

else if(action.compare("replace")==0){ myfile >> x; list.replacex(x);}

else if(action.compare("removeFirst")==0) list.removeFirst();

else if(action.compare("removeLast")==0) list.removeLast();

else if(action.compare("remove")==0) list.removex();

else if(action.compare("removeAndRetreat")==0) list.removeAndRetreat();

else if(action.compare("removeAndAdvance")==0) list.removeAndAdvance();

else if(action.compare("display")==0) list.display();

}
}



myfile.close();

}

//thanks
Topic archived. No new replies allowed.