Hi I got bumped back in my progress because I am getting a bunch of errors.
Ok I fixed some errors but still complaining about conversion for shared ptrs. I am trying to convert the pointers to smart pointers and use auto where i can but its not working. >< Please help
Get rid of the shared pointers since no pointers are shared.
Line 32 should be Node <ItemType> *getNext() const
Line 80: Function currently doesn't return anything if the "else" clause is executed.
Line 155 should be for (size_t position = 1;
Line 189: The function doesn't return anything if ableToSet is false.
I am trying to switch over to smart pointers but still working with them. The else part of getNodeAt is suppose to throw an exception but it was not working. It has no build errors, I need to make the exception handler work (the commented out areas). I tested it but I cant get the exception part to work.
shared_ptr<Node<ItemType>> getNodeAt(constint position) const //Locates a specified node in a linked list.
{ //@pre position is the number of the desired node.
if ((position >= 1) & (position <= itemCount)) //position >=1 and position <= itemCount.
{ //@post the node is found and a pointer to it is returned.
shared_ptr<Node<ItemType>> curPtr = headPtr; //@param position the number of the node to locate.
for (int skip = 1; skip < position; skip++) //@return a pointer to the node at the given position.
curPtr = curPtr->getNext();
return curPtr;
}
throw PrecondViolatedExcept("invalid position");
}
I would reiterate that shared_ptr is not appropriate here.
The project is going to expand a lot, I was told I should use them maybe for future needs. Thank you that fixed the exception problem :) . How would I make a copy constructor for the LinkedList class? Id have to take in a reference object and work it to copy the info I am just not sure how to make it work. ><
I was told I need to for my project by my teacher. I need to intake information from a file, and work it so the user can search by keyword instead of position. I need to make a child class of the linkedlist class to do all the work. Then I have to work main after to do some specifics.
Its nothing like I have done before. I am just lost started off too fast in the class. I am working on the data handling right now but hit another road block. I was reading the info from the file but some lines of info exceed the amount that getline can put into a string, so they are ending up on the next line and not being held in one node as it sits. I really don't want to do character arrays for each line. -Scratch that it was just overflowing on the output screen max of 80 chars it is holding the whole line ><.
LinkedList(const LinkedList<ItemType>& aList ) : itemCount(0) // initialise
{
for( int i = 1 ; i <= aList.getLength() ; ++i ) // note: first position is 1
this->insert( i, aList.getEntry(i) ) ;
}