locked
Unreferenced local variable

    Question

  •  

    Why do I keep getting a warning of "unreferenced local variable"?

     

    #ifndef H_LinkedListType

    #define H_LinkedListType

    #include <iostream>

    #include <cassert>

    using namespace std;

    template <class Type>

    struct nodeType

    {

    Type info;

    nodeType<Type> *link;

    };

    template<class Type>

    class linkedListType

    {

    template<class Type>

    friend ostream& operator<<(ostream&, const linkedListType<Type>&);

    public:

    const linkedListType<Type>& operator=

    (const linkedListType<Type>&);

    void initializeList();

    bool isEmptyList();

    int length();

    void destroyList();

    Type front();

    Type back();

    bool search(const Type& searchItem);

    void insertFirst(const Type& newItem);

    void insertLast(const Type& newItem);

    void deleteNode(const Type& deleteItem);

    linkedListType();

    linkedListType(const linkedListType<Type>& otherList);

    ~linkedListType();

    void deleteSmallest();

    protected:

    int count;

    nodeType<Type> *first;

    nodeType<Type> *last;

    private:

    void copyList(const linkedListType<Type>& otherList);

    };

    template<class Type>

    void linkedListType<Type>:eleteSmallest()

    {

    nodeType<Type> deleteSmallest; // Why do I keep getting a warning of "unreferenced local variable"?

    }

    template<class Type>

    bool linkedListType<Type>::isEmptyList()

    {

    return(first == NULL);

    }

    template<class Type>

    linkedListType<Type>::linkedListType()

    {

    first = NULL;

    last = NULL;

    count = 0;

    }

    template<class Type>

    void linkedListType<Type>:estroyList()

    {

    nodeType<Type> *temp;

    while(first != NULL)

    {

    temp = first;

    first = first->link;

    delete temp;

    }

    last = NULL;

    count = 0;

    }

    template<class Type>

    void linkedListType<Type>::initializeList()

    {

    destroyList();

    }

    template<class Type>

    int linkedListType<Type>::length()

    {

    return count;

    }

    template<class Type>

    Type linkedListType<Type>::front()

    {

    assert(first != NULL);

    return first->info;

    }

    template<class Type>

    Type linkedListType<Type>::back()

    {

    assert(last != NULL);

    return last->info;

    }

    template<class Type>

    bool linkedListType<Type>:earch(const Type& searchItem)

    {

    nodeType<Type> *current;

    bool found;

    current = first;

    found = false;

    while(current != NULL && !found)

    if(current->info == searchItem)

    found = true;

    else

    current = current->link;

    return found;

    }

    template<class Type>

    void linkedListType<Type>::insertFirst(const Type& newItem)

    {

    nodeType<Type> *newNode;

    newNode = new nodeType<Type>;

    assert(newNode != NULL);

    newNode->info = newItem;

    newNode->link = first;

    first = newNode;

    count++;

    if(last == NULL)

    last = newNode;

    }

    template<class Type>

    void linkedListType<Type>::insertLast(const Type& newItem)

    {

    nodeType<Type> *newNode;

    newNode = new nodeType<Type>;

    assert(newNode != NULL);

    newNode->info = newItem;

    newNode->link = NULL;

    if(first == NULL)

    {

    first = newNode;

    last = newNode;

    count++;

    }

    else

    {

    last->link = newNode;

    last = newNode;

    count++;

    }

    }

    template<class Type>

    void linkedListType<Type>:eleteNode(const Type& deleteItem)

    {

    nodeType<Type> *current;

    nodeType<Type> *trailCurrent;

    bool found;

    if(first == NULL)

    cerr<<"Can not delete from an empty list.\n";

    else

    {

    if(first->info == deleteItem)

    {

    current = first;

    first = first->link;

    count--;

    if(first == NULL)

    last = NULL;

    delete current;

    }

    else

    {

    found = false;

    trailCurrent = first;

    current = first->link;

    while(current != NULL && !found)

    {

    if(current->info != deleteItem)

    {

    trailCurrent = current;

    current = current->link;

    }

    else

    found = true;

    }

    if(found)

    {

    trailCurrent->link = current->link;

    count--;

    if(last == current)

    last = trailCurrent;

    delete current;

    }

    else

    cout<<"Item to be deleted is not in the list."<<endl;

    }

    }

    }

     

    template<class Type>

    ostream& operator<<(ostream& osObject, const linkedListType<Type>& list)

    {

    nodeType<Type> *current;

    current = list.first;

    while(current != NULL)

    {

    osObject<<current->info<<" ";

    current = current->link;

    }

    return osObject;

    }

    template<class Type>

    linkedListType<Type>::~linkedListType()

    {

    destroyList();

    }

    template<class Type>

    void linkedListType<Type>::copyList

    (const linkedListType<Type>& otherList)

    {

    nodeType<Type> *newNode;

    nodeType<Type> *current;

    if(first != NULL)

    destroyList();

    if(otherList.first == NULL)

    {

    first = NULL;

    last = NULL;

    count = 0;

    }

    else

    {

    current = otherList.first;

    count = otherList.count;

    first = new nodeType<Type>;

    assert(first != NULL);

    first->info = current->info;

    first->link = NULL;

    last = first;

    current = current->link;

    while(current != NULL)

    {

    newNode = new nodeType<Type>;

    assert(newNode!= NULL);

    newNode->info = current->info;

    newNode->link = NULL;

    last->link = newNode;

    last = newNode;

    current = current->link;

    }

    }

    }

    template<class Type>

    linkedListType<Type>::linkedListType

    (const linkedListType<Type>& otherList)

    {

    first = NULL;

    copyList(otherList);

    }

    template<class Type>

    const linkedListType<Type>& linkedListType<Type>::operator=

    (const linkedListType<Type>& otherList)

    {

    if(this != &otherList)

    copyList(otherList);

    return *this;

    }

    #endif

    Monday, October 13, 2008 8:11 PM

Answers

  • deleteSmallest isn't used anywhere inside your code.  In fact, the function doesn't do anything at all.  Finish your code.
    Monday, October 13, 2008 11:32 PM
    Moderator

All replies

  • deleteSmallest isn't used anywhere inside your code.  In fact, the function doesn't do anything at all.  Finish your code.
    Monday, October 13, 2008 11:32 PM
    Moderator
  • Okay. Thank you. I am still learning. I will continue working on it.

     

     

    Thursday, October 16, 2008 11:40 PM