cosmicsafari
July 23rd, 2008, 04:40 PM
Everytime i attempt to run my program i get this error:
Unhandled exception at 0x00411725 in test.exe: 0xC0000005: Access violation reading location 0xcccccccc.
I have read this has something to do with bad ariables but i can't seem to find any =S
The code is as follows:
#include "LinkedList.h"
#include <conio.h> //used for getch();
LinkedList::LinkedList(){ //constructor
count = 0;
Head = NULL;
Previous = NULL;
}
//--------------Function to create new munros(nodes) and populate them with data---------------------------
void LinkedList:: generateHills(int A,int B,bool C,int D,int E){
MunroRecord *Next_Node; //declare pointer to node called nextNode
Next_Node = new MunroRecord; //create new node
Next_Node->height = A; //set value of hill height to equal parameter A
Next_Node->distanceFromHome = B; //set value of distance from home to equal parameter B
Next_Node->climbed = C; //set value of previous climbed to equal parameter C
Next_Node->timesClimbed = D; //set value of times climbed to equal parameter D
Next_Node->gridReference = E; //set value of grid reference to equal parameter E
Next_Node->Head = FirstNode; // give the node’s next field the value currently in FirstNode
//i.e. the new node now points to the old first node
FirstNode = Next_Node; //and the FirstNode now points to the new node
FirstNode->Previous = Next_Node;
count++; // 1 is added to counter to include the new node in the total number of nodes
if(LastNode == NULL){ //if there are currently no nodes in the list the linked list’s
LastNode = Next_Node; // “LastNode” field also points to the new node, as it both the
} //first and LastNode node.
}
MunroRecord* LinkedList::getFirst(){ return FirstNode;}
//int LinkedList::Munro_Count(){ return count;}
//--------------------Insertion Sort function to sort linked list via height--------------
void LinkedList::Insertion_Sort(){
MunroRecord *current = FirstNode->Head; //2 variables used for searching
MunroRecord *trailCurrent = FirstNode; //through the linked list
//now use them to find how much of the list is currently
//in order, by starting at the FirstNode and continuing so long
//as the data in one node is greater than that in the previous node
while(current->height > trailCurrent->height){
trailCurrent = current;
current = current->Head;
}
MunroRecord *lastInOrder = trailCurrent; //place the information obtained
MunroRecord *firstOutOfOrder = current; //above into these variables
//now start at the end of the ordered part of the list and deal one
//at a time with the unordered nodes
while(lastInOrder->Head != NULL){
//first special case - the first out of order node is greater
//than any in the ordered list and stays where it is, but the pointers
//"lastInOrder" & "firstOutOfOrder" must now be made to point to
//the nodes along one
if(lastInOrder->height < firstOutOfOrder->height){
lastInOrder = firstOutOfOrder;
firstOutOfOrder = firstOutOfOrder->Head; //see below - repeat
} //but no harm done
else{
//second special case - the next node must go to the start of the list
//the following line is highlighted by Visual Studio when it is run--------------
if(LastNode->height > firstOutOfOrder->height){
lastInOrder->Head = firstOutOfOrder->Head;
firstOutOfOrder->Head = FirstNode;
FirstNode = firstOutOfOrder;
}
//otherwise go through the linked list to find where the
//first out of order node goes and rearrange the links
//accordingly
else{
current = FirstNode->Head;
trailCurrent = FirstNode;
while(current->height < firstOutOfOrder->height){
trailCurrent = current;
current = current->Head;
}
lastInOrder->Head = firstOutOfOrder->Head;
firstOutOfOrder->Head = current;
trailCurrent->Head = firstOutOfOrder;
}
firstOutOfOrder = lastInOrder->Head; //see above - repeat
}
}
}
Any help would be greatly appreciated ^_^
Unhandled exception at 0x00411725 in test.exe: 0xC0000005: Access violation reading location 0xcccccccc.
I have read this has something to do with bad ariables but i can't seem to find any =S
The code is as follows:
#include "LinkedList.h"
#include <conio.h> //used for getch();
LinkedList::LinkedList(){ //constructor
count = 0;
Head = NULL;
Previous = NULL;
}
//--------------Function to create new munros(nodes) and populate them with data---------------------------
void LinkedList:: generateHills(int A,int B,bool C,int D,int E){
MunroRecord *Next_Node; //declare pointer to node called nextNode
Next_Node = new MunroRecord; //create new node
Next_Node->height = A; //set value of hill height to equal parameter A
Next_Node->distanceFromHome = B; //set value of distance from home to equal parameter B
Next_Node->climbed = C; //set value of previous climbed to equal parameter C
Next_Node->timesClimbed = D; //set value of times climbed to equal parameter D
Next_Node->gridReference = E; //set value of grid reference to equal parameter E
Next_Node->Head = FirstNode; // give the node’s next field the value currently in FirstNode
//i.e. the new node now points to the old first node
FirstNode = Next_Node; //and the FirstNode now points to the new node
FirstNode->Previous = Next_Node;
count++; // 1 is added to counter to include the new node in the total number of nodes
if(LastNode == NULL){ //if there are currently no nodes in the list the linked list’s
LastNode = Next_Node; // “LastNode” field also points to the new node, as it both the
} //first and LastNode node.
}
MunroRecord* LinkedList::getFirst(){ return FirstNode;}
//int LinkedList::Munro_Count(){ return count;}
//--------------------Insertion Sort function to sort linked list via height--------------
void LinkedList::Insertion_Sort(){
MunroRecord *current = FirstNode->Head; //2 variables used for searching
MunroRecord *trailCurrent = FirstNode; //through the linked list
//now use them to find how much of the list is currently
//in order, by starting at the FirstNode and continuing so long
//as the data in one node is greater than that in the previous node
while(current->height > trailCurrent->height){
trailCurrent = current;
current = current->Head;
}
MunroRecord *lastInOrder = trailCurrent; //place the information obtained
MunroRecord *firstOutOfOrder = current; //above into these variables
//now start at the end of the ordered part of the list and deal one
//at a time with the unordered nodes
while(lastInOrder->Head != NULL){
//first special case - the first out of order node is greater
//than any in the ordered list and stays where it is, but the pointers
//"lastInOrder" & "firstOutOfOrder" must now be made to point to
//the nodes along one
if(lastInOrder->height < firstOutOfOrder->height){
lastInOrder = firstOutOfOrder;
firstOutOfOrder = firstOutOfOrder->Head; //see below - repeat
} //but no harm done
else{
//second special case - the next node must go to the start of the list
//the following line is highlighted by Visual Studio when it is run--------------
if(LastNode->height > firstOutOfOrder->height){
lastInOrder->Head = firstOutOfOrder->Head;
firstOutOfOrder->Head = FirstNode;
FirstNode = firstOutOfOrder;
}
//otherwise go through the linked list to find where the
//first out of order node goes and rearrange the links
//accordingly
else{
current = FirstNode->Head;
trailCurrent = FirstNode;
while(current->height < firstOutOfOrder->height){
trailCurrent = current;
current = current->Head;
}
lastInOrder->Head = firstOutOfOrder->Head;
firstOutOfOrder->Head = current;
trailCurrent->Head = firstOutOfOrder;
}
firstOutOfOrder = lastInOrder->Head; //see above - repeat
}
}
}
Any help would be greatly appreciated ^_^