I am having a compiler error that causes a screen to pop up that says break or continue. I know it is something wrong with my program but I am at a lost as to what it is. I was just trying to test the first function as you can see from my main program at the bottom. Any help would be deeply appreciated I have been working non stop on this for days and haven't figured it out.
Here is my header file:

#include <iostream>
using namespace std;

struct Node 
{
    char cvalue;
    double dvalue;
    int keyvalue;
    Node *next;
};

Here is my .cpp file

#include "SimplelinkedListLab_2.h"


class SimpleLinkedList
{
private:
    Node *first; // This is the only member variable your are allowed!
public:
    SimpleLinkedList(); // Default constructor
    ~SimpleLinkedList(); // Destructor must delete all nodes in the list
    bool empty();// returns true if list is empty
    void insert (char, double, int);
    void remove(int);
    int listCount();
    bool getValue(int, char & c, double & d);
    void minValue( char & cval, double & dval);
    void maxValue(char & cval, double & dval);
    void displayList( ostream & out);
};


SimpleLinkedList ::SimpleLinkedList()
{
    first = new Node;
    first -> next = NULL;
}

SimpleLinkedList :: ~SimpleLinkedList()
{
    Node *temp = new Node;
    while (first != NULL)
    {
        temp = first -> next;
        delete temp;
    }
}

bool SimpleLinkedList :: empty()
{
    if (first -> next == NULL)
        return true;
    else
        return false;
}
void SimpleLinkedList :: insert( char c, double d, int key)
{
    char cvalue = c;
    double dvalue = d;
    int keyvalue = key;
    Node *tmp = new Node;
    tmp -> dvalue = dvalue;
    tmp -> cvalue = cvalue;
    tmp -> keyvalue = keyvalue;
    if (tmp == NULL)
        return;
    if (first == NULL || key < first -> keyvalue)
    {
        tmp -> next = first;
        first = tmp;
    }
    else
    {
        Node *pred = first;
        while (pred -> next != NULL && pred -> next -> keyvalue < key)
        {
            pred = pred -> next;
        }
        tmp -> next = pred -> next;
        pred -> next = tmp;
    }
    delete tmp;
}

void SimpleLinkedList :: remove(int key)
{
    Node *pred = NULL;
    Node *tmp = first;

    if (tmp == NULL)
        return;
    if (tmp -> keyvalue == key)
    {
        first = tmp -> next;
        delete tmp;
        return;
    }
    tmp = tmp -> next;
    while (tmp != NULL && tmp -> keyvalue != key)
    {
        pred = tmp;
        tmp = tmp -> next;
    }
    if (tmp != NULL)
    {
        pred -> next = tmp -> next;
        delete tmp;
    }
}

int SimpleLinkedList :: listCount()
{
    Node *tmp = first;
    int count = 0;
    while (tmp -> keyvalue != NULL)
    {
        count++;
    }
    delete tmp;
    return count;
}
// Returns the number of nodes in the list.
void SimpleLinkedList :: displayList( ostream & out)
{
    Node *tmp = first;
    while(tmp != NULL)
    {
        out << tmp -> cvalue << " "; 
        out << tmp -> dvalue << " ";
        out << tmp -> keyvalue << " ";
        tmp = tmp -> next;
    }
    cout << endl;
}
bool SimpleLinkedList :: getValue(int key, char & c, double & d)
{
    Node *tmp = first;

    while (tmp != NULL && tmp -> keyvalue != key)
    {
        tmp = tmp -> next;
    }
    c = tmp -> cvalue;
    d = tmp -> dvalue;
    if (tmp == NULL)
        return false;
    else
        return true;
}

void SimpleLinkedList :: minValue( char & cval, double & dval)
{
    Node *tmp = first;
    int min = cval;
    double dmin = dval;
    while (tmp != NULL)
    {
        if (cval > tmp -> cvalue)
            tmp = tmp -> next;
        else
            min = cval;
    }
    delete tmp;
    Node *tmp2 = first;
    while (tmp != NULL)
    {
        if (dval > tmp -> dvalue)
            tmp = tmp -> next;
        else
            dmin = dval;
    }
    delete tmp2;
}
void SimpleLinkedList :: maxValue(char & cval, double & dval)
{
    Node *tmp = first;
    int max = cval;
    double dmax = dval;
    while (tmp != NULL)
    {
        if (cval > tmp -> cvalue)
            tmp = tmp -> next;
        else
            max = cval;
    }
    delete tmp;
    Node *tmp2 = first;
    while (tmp != NULL)
    {
        if (dval > tmp -> dvalue)
            tmp = tmp -> next;
        else
            max = dval;
    }
    delete tmp2;
};


int main ()
{
    SimpleLinkedList list;
    list.insert('A', 1, 1);
    list.displayList(cout);
    system ("PAUSE");
}

Again any help would be much appreciated

Recommended Answers

All 2 Replies

Using Visual Studio? Press F5 with the project open.

First, your constructor and destructor are bogus. This is how it should be:

SimpleLinkedList ::SimpleLinkedList()
{
    first = new Node;
    first -> next = NULL;

// Don't forget to initialize node's member fields. Unless
// Node has a default constructor that initializes them for
// you, they will contain random data values.
    first->cvalue = 0;
    first->dvalue = 0;
    first->keyvalue = 0;
}


SimpleLinkedList :: ~SimpleLinkedList()
{
// Implement a proper head-first deletion routine.
    while (first != 0)
    {
        Node* temp = first;
        first = first->next;
        delete temp;
    }
}

I'd look further, but this will get you started. In any case, you need to do a thorough analysis of your code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.