Linked List

Can i return the value of a linked list as 1 integer?
for example: ->5->8->3 represented as a decimal number 583
where it is equal 1 integer NOT 3 integers beside each others.

if yes how please?
help please
Yes it's possible. I don't know how your linked list look like. I should be similar:

1
2
3
4
5
6
int val = 0;
for(node *n = list.First(); n != NULL; n = n->Next()) // or so..
{
  val *= 10;
  val += n->val;
}
@coder777 thanks man. but your code adds the linked list values, and i wanna return the whole linked list values as one integer!
->5->8->3

5*100+8*10+3*1=583

I think that was what coder777 was saying

int n=0;
for(node *x = list.first(); n!=NULL; n = n->Next()){

val+=x*10^n;
n++;
}





Last edited on
Thx man, i feel stupid :S simple math xD
Ha, its all good. Everyone has been there at one point or another.
Topic archived. No new replies allowed.