Why am I getting nothing printed by this program
1 2 3 4
|
When I try to print the program I get nothing
Enter a list of integers ending with -999.
12 45 76 89 -999
|
When I press "enter" to print the list
I get this:
1 2 3
|
Process returned 0 (0x0) execution time : 89.943 s
Press any key to continue.
|
Nothing printed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include<iostream>
#include<cassert>
using namespace std;
struct nodeType
{
int info;
nodeType *link;
};
class linkedList
{
private:
nodeType *first;
nodeType *last;
int count;
public:
linkedList();
void print();
void display();
void buildListBackward();
};
linkedList::linkedList()
{
first = NULL;
count = 0;
}
void linkedList :: buildListBackward()
{
nodeType *first, *newNode;
int num;
cout << "Enter a list of integers ending with -999. "<< endl;
cin >> num;
first = NULL;
while (num != -999)
{
newNode = new nodeType; //create a node
assert (newNode != NULL);
newNode->info = num;
newNode->link = first;
first = newNode;
cin >> num;
}
}
void linkedList::print()
{
nodeType * current; //pointer to traverse the list
current = first; //set current point to the first node
while (current != NULL) //while more data to print
{
cout << current->info << " ";
current = current->link;
}
}
void linkedList::display() {
nodeType* ptr, *first;
ptr = first;
while (ptr != NULL) {
cout<< ptr->info <<" ";
ptr = ptr->link;
}
}
int main()
{
linkedList myList;
myList.buildListBackward();
// myList.display();
myList.print();
}
|
Topic archived. No new replies allowed.