Unsorted List

This is a discussion on Unsorted List within the C++ Programming forums, part of the General Programming Boards category; I am trying to figure out how to create a program for an unsorted list class. I need to use ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    2

    Unsorted List

    I am trying to figure out how to create a program for an unsorted list class. I need to use this header file and can't change it. I need help creating the RetrieveItem, DeleteItem, inGetNextItem, PrintList and InsertItem to add to my implementation file. I just can't seem to figure it out. Any help or suggestions are greatly appreciated.

    Thanks,
    Robert

    Code:
    #indef UNSORTEDTYPE_H
    #define UNSORTEDTYPE_H
    const int MAX_ITEMS=10;
    class UnsortedType
    {
    public:
        UnsortedType();
        bool IsFull() const;
        int LengthIs() const;
        bool RetrieveItem (int item);
        bool InsertItem (int item);
        bool DeleteItem(int item);
        void ResetList();
        int GetNextItem();
        void ResetList();
        void PrintList();
    private:
        int length;
        int info[MAX_ITEMS];
        int currentPos;
    };

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    2

    Here is what I have so far

    Here is what I have so far. I know that I have some things that are incorrect.

    Robert

    Code:
    #include "unsorted.h"
    
    UnsortedType()::UnsortedType()
    {
        length = 0;
    }
    
    bool UnsortedType::IsFull() const
    {
        return (length == MAX_ITEMS);
    }
    
    int UnsortedType::LengthIs() const
    {
        return length;
    }
    
    bool UnsortedType::FindItem( int item )
    
    
    bool UnsortedType::InsertItem( int item )
    {
        if (!IsFull())
        {
            info[length] = item;
            length++;
        }
    }
    
    bool UnsortedType::DeleteItem( int item )
    {
        int location = 0;
        info[location] = info[length - 1];
        length--;
    }
    
    void UnsortedType::ResetList()
    {
        currentPos = -1;
    }
    
    int UnsortedType::GetNextItem()
    {
        int item;
        currentPos++;
        item = info[currentPos];
    }
    
    void UnsortedType::ClearList()
    {
        length = 0;
    }
    
    void UnsortedType::PrintList()
    {
        int length;
    
        ResetList();
        length = LengthIs();
        for (int counter = 1; counter <= length; counter++)
        {
            GetNextItem();
            return info[MAX_ITEMS];
        }
    }

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > I know that I have some things that are incorrect.
    So write a main.cpp which calls your class and start testing it.

    And if you're unsure what you're supposed to do, use pencil and paper to sketch out the data structure and what happens to it when you apply certain operations on it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 08:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 04:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21