On Thu, 2013-02-21, Paul N wrote:
> You haven't asked a question, but I'll make one comment:
>
>
> On Feb 21, 6:33*am, Logan Lee <guniti...@gmail.com> wrote:
>> #include <iostream>
>> using namespace std;
>>
>> struct node {
>> * * * *int data;
>> * * * *node* next;
>>
>> };
>>
>> int main() {
>> * * node* head;
>> * * node* newnode;
>> * * head=NULL;
>>
>> * * for (int i=0; i<3; i++) {
>
>
>> * * * * newnode=new node;
>> * * * * newnode->data=i+1;
>> * * * * newnode->next=head;
>> * * * * head=newnode;
>
> Part of the idea behind C++ is that you have functions hidden in your
> classes to do this sort of messy stuff, so that the users of the class
> don't have to worry about it. The above four lines might then be
> reduced to something like:
>
> mylist.addnode(i+1);
And then you address more and more weaknesses, until finally you end
up with std::list. It would be interesting to follow such a
transformation.
To the original poster: your code is basically C code. It's fine to
learn how to use the C part of C++ this way, but it's also important
to understand that you almost never write code like this in C++. You
use the standard containers -- sometimes std::list, but more often
std::vector and some others. You yourself can concentrate on more
interesting tasks.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
|