hi there
can anyone help me with my code? it can be compiled successfully in vc++6.0, however it fails to run.
here's the code:
//set.h
#include <iostream>
using namespace std;
struct Node{
char element;
Node* next;
};
class Set {
public:
Set();
Set(char start, char end);
void printSet();
private:
Node* head;
};
//set.cpp
#include <iostream>
#include "set.h"
Set::Set() {
head = NULL;
}
Set::Set(char start, char end) {
char temp = start;
Node* ptemp = new Node;
ptemp->element = temp;
ptemp->next = NULL;
head = ptemp;
temp++;
while (temp != end){
ptemp = ptemp->next;
ptemp->element = temp;
temp++;
}
}
void Set::printSet(){
cout << "[";
if (head != NULL){
Node* pprint = head;
cout << pprint->element;
pprint = pprint->next;
while (pprint != NULL) {
cout << ',' << pprint->element;
pprint = pprint->next;
}
}
cout << "]";
}
//main.cpp
#include "set.h"
using namespace std;
void main() {
Set B('A', 'Z');
B.printSet();
}
//basically i want to store A~Z in a linked list and print it out