Hello,
if I compile this code it crashes at the if statement comparison. Giving me an access violation. it is meant to check, wether the elements stored in the linked list are ascending. I would really appretiate help.
Thanks stk123
#include <fstream.h>
typedef char Item;
class Node {
public:
Item data;
Node* next;
};
int main()
{
typedef Node* NodePtr;
NodePtr hdList = new Node;
NodePtr newNode = new Node;
NodePtr lastPtr = new Node;
NodePtr newPtr = new Node;
NodePtr curentPtr = new Node;
NodePtr temp1 = new Node;
NodePtr temp2 = new Node;
NodePtr temp3 = new Node;
char ch;
char le;
char ch1;
char ch2;
ifstream infile ("input_data_file.txt");
ofstream outfile ("output_file_1.txt");
ifstream infile2 ("delete_data_file.txt");
ofstream outfile2 ("output_file_2.txt");
infile.get(ch);
hdList -> data = ch;
hdList -> next = NULL;
//infile into linked list
while (infile.get(ch))
{
NodePtr newNode = new Node;
newNode -> data = ch;
newNode -> next = hdList;
hdList = newNode;
}
//bouble sort
newPtr = hdList;
curentPtr = hdList;
lastPtr = hdList;
while (lastPtr != NULL)
{
newPtr = curentPtr;
curentPtr = curentPtr -> next;
lastPtr = curentPtr -> next;
ch1 = curentPtr -> data;
ch2 = lastPtr -> data;
if (ch1 > ch2 )
{
ch1 = '3';
}
}
//linked list into outfile
while (hdList!=NULL){
le = hdList -> data;
hdList = hdList -> next;
outfile.put(le);
}
}