- #1
needOfHelpCMath
- 72
- 0
What is wrong with my program? I am so close to finish it. May anyone tell me what is wrong and how to fix it.
HTML:
#include <iostream>
#include <cstdlib>
using namespace std;
class Node {
public:
Node();
Node* prev;
string key;
Node* next;
};
Node::Node(){
prev = 0;
next = 0;
}
class LinkedList {
public:
LinkedList();
void Insert(string key);
void Print();
Node* Find(string key);
void Delete(Node* x);
Node* head;
};
LinkedList::LinkedList(){
head=0;
}
void LinkedList::Insert(string key) {
Node* n;
n=new Node;
n->key= key;
n->next = head;
head=n;
return;
}
void LinkedList::Print() {
Node* n;
cout <<"Print"<<endl;
n=head;
while (n!=0){
cout << n->key << endl;
n=n->next;
}
return;
}
/*void LinkedList::Find() {
Node* n;
cout <<"Print"<<endl;
n=head;
while (n!=0){
cout << n->key << endl;
n=n->next;
}
return;
}
*/
int main(){
string line;
LinkedList l;
while (true){
getline(cin, line);
if (line.empty()){
break;
}
l.Insert(line);
}
l.Print();
/*
n = l.Find("test3");
cout << "found key "<< n->key << endl;
*/
return 0;
}
HTML:
*What I got correct*
1. Unit test
1/1
Code Compiles
2. Compare output:
1/1
Input
100
200
Your output :
Print
200
100
3. Unit test
1/1
Test Node Class
4. Unit test
1/1
Test Linked List Insert Function
5. Unit test
1/1
Insert Twice
6. Unit test
0/1
Find Node Test