How would I go to create a long using a single linked list? I need to get started but I dont know how. Is it possible that someone can show me how to get the basic BigInt?
Asked
Active
Viewed 106 times
0
-
What language are you using? – irrelephant Nov 08 '12 at 08:38
-
5Welcome to Stack Overflow! We encourage you to [research your questions](http://stackoverflow.com/questions/how-to-ask). If you've [tried something already](http://whathaveyoutried.com/), please add it to the question - if not, research and attempt your question first, and then come back. – Nov 08 '12 at 08:55
1 Answers
-1
Python2.7 doesn't have bigint, but int and longs, see python docs. Python3 has only integers. However in practice, because Python it is not a typed language you can change between long and int seamlessly. As soon as maxint is reached the number is converted into a long, which does not have a size restriction.
>>> import sys
>>> sys.maxint
9223372036854775807
>>> 2**10
1024
>>> 2**20
1048576
>>> 2**50
1125899906842624
>>> 2**100
1267650600228229401496703205376L
You can find an implementation of a linked list here on SO. Typically a list can carry any object, because Python is dynamically typed. I can't see what linked lists have to do with longs.
-
-
Did I make the code up? This is Python2.7 and uses 'L' for longs. From 3.0 onwards there are only ints. 2.7.2 is still the reference implementation. – RParadox Nov 08 '12 at 17:50
-
-
Read the docs: "There are four distinct numeric types: plain integers, long integers, floating point numbers, and complex numbers." Why did long integers and sys.maxint exist in the first place? If you want to correct someone, be more specific. – RParadox Nov 08 '12 at 17:55