Extreamly large numbers in C++
This would probably be most primitive of all primitive linked lists.It misses some basic functionality too like delete but this way its a bit easier to understand.In this form you can use it only to store int values.Its singly linked,if you wont double you must add another pointer in class member.Next points to next member and the other would point to previous. Anyway i think it wont solve your problem (which is quite interesting to me)because every object is its own entity,every int inside is just an int.you can store numbers and make a very long list but it wont be one entity.You could do almost the same thing with the array of int but that way you again have only ints lined up for printing maybe but not to make any calculations on it as a whole. I cant figure out the string trick because i can store a number in the string but when i extract one from inside and assign it back to int i get its decimal value but cant get back to ascii. …………………………………………………………………………………….. #include <cstdlib> #include <iostream>
using namespace std;
class member{ public: member *next;
int value;
member(int x=0):value(x){cout<<"created member: "<<value<<endl;}
};
class list{ public: member *head;
list():head(NULL){cout<<endl<<"created list with members:"<<endl;}
member put( member &x);
void print();
}; member list::put(member &x){ member *tmp=head; head=&x; head->next=tmp;
}
void list::print(){ member *tmp=head; while(tmp) { cout<<tmp->value<<"\t"; tmp=tmp->next; } cout<<endl; }
int main(int argc, char *argv[])
{
member q(2);
member a(3);
member z(4);
list lst;
lst.put(q);
lst.put(a);
lst.put(z);
lst.print();
system("PAUSE");
return EXIT_SUCCESS;
}
……………………………………………………………………………………… Anyway an interesting problem…
global1 wrote: This would probably be most primitive of all primitive linked lists.It misses some basic functionality too like delete but this way its a bit easier to understand.In this form you can use it only to store int values.Its singly linked,if you wont double you must add another pointer in class member.Next points to next member and the other would point to previous.
Anyway i think it wont solve your problem (which is quite interesting to me)because every object is its own entity,every int inside is just an int.you can store numbers and make a very long list but it wont be one entity.You could do almost the same thing with the array of int but that way you again have only ints lined up for printing maybe but not to make any calculations on it as a whole. I cant figure out the string trick because i can store a number in the string but when i extract one from inside and assign it back to int i get its decimal value but cant get back to ascii.
i think the problem was solved already and dont write the code for the guy. he wont learn if you do all the work for him.
global1 wrote: Happy 2008!!! So ok i wont.But why not? A Q4U:Is it better to let someone discover the hot watter or to help him understand why the water is hot?I personally more appreciate later approach. but anyway,i wont post this way again Thanx Bye
you're right that it's good to help people to understand things, but it is better if you only open the door for them rather than push them through it. just give suggestions and input unless someone asks for more detailed assistance. i dont mean to criticize, but to give a bit of wisdom.