I am continuing to put together this project and was a little confused on getting the length of my list. I thought u had to traverse a list and then count how many times it goes through.
length() is the one i was trying to use to count the things in the list (head->item)
header file
Code:struct node { char item; node *next; }; class Newstring { public: char display() const; int pointers(); int length(); private: char s; node *head; node *first; node *second; node *last; };
theCode:#include "4dot6.cpp" char Newstring::display()const { char s='s'; cout << s << endl; return s; } int Newstring::length() { head->item='a'; first->item='v'; second->item='e'; last->item='d'; head->next=first; first->next=second; second->next=last; last->next=NULL; while(head->next!=NULL) { cout << head->item << endl; head=head->next; } } int main() { Newstring a; a.display(); a.length(); system("pause"); return 0; }



LinkBack URL
About LinkBacks



