Place node struct node int data node next many texts

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: edList { public: // the following are as before // the LinkedList(); // constructor ~LinkedList(); // destructor void AddToTail(const int&); void AddToTail(const // previous store function bool IsEmpty(); int RemoveFromHead(); // previous retrieve function Applied Programming Here is an alternative: Place the declaration of node outside the class. Place node struct node { int data; node* next; }; Many texts use this approach although the node Many struct is not encapsulated. struct Applied Programming Applied Programming void Insert(const int&); void Insert(const bool Locate(const int&, int&); &, int bool Delete(const int&, int&); &, int // all using comparison private: struct node; typedef node *nodePtr; struct node { int data; nodePtr next; }; nodePtr head; }; #endif Applied Programming void LinkedList::Insert(const int& newdata) void LinkedList::Insert(const newdata { nodePtr curr, prev, newnode; prev newnode curr = head; prev = 0; while (curr!=0 && ListDataCmp(newdata,curr->data) > 0) !=0 ListDataCmp(newdata,curr { prev = curr; curr curr = curr->next; curr } newnode = new node; newnode->data = newdata; >data newdata // needs copy constructor if (prev != 0) prev->next = newnode; >next newnode else head = newnode; head newnode newnode->next = curr; >next curr } Applied Programming Many of the processes carried out on lists (and in Many fact arrays) are sequential such as fact • displaying all contents in order W e will see later how we can create a separate We iterator class to perform the process. iterator For now we will add three functions to our class. • calculating statistics W e need to be able to iterate through the list from We iterate through start to finish. start These three functions require the addition of one These more piece of private data in the class. more A current location – call it current. current call current How can we incorporate this process? Applied Programming This variable needs to be set to the head of the This list at the start of the iteration. So list void LinkedList::SetIt...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern