3:53 is a jiff?
The first thing I noticed with your code is that you're passing a vector by value. Usually it's a much better idea to pass STL containers as references or pointers because it can be quite expensive to copy them.
When I compile your code, I get two warnings and one error. Here's the error:
Code:
nodes.[i-1]->next = nodes[i];
It seems you have an extra '.'.
The warnings are on these lines:
Code:
for(size; size>=0; size--)
for(size-2; size>=0; size--)
The first part of those for loops does nothing and can be left out.
Once I removed the bothersome '.', your program compiled correctly and ran without segfaulting.
[edit] I ran your program quickly though GDB.
Code:
GNU gdb 5.2.1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License,
welcome to change it and/or distribute copies of it under certain
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" fo
This GDB was configured as "i686-pc-mingw32"...
(gdb) break 33
Breakpoint 1 at 0x401549: file tempjunior2.cpp, line 33.
(gdb) r
Starting program: tempjunior2.exe
Breakpoint 1, main () at tempjunior2.cpp:33
33 cin.ignore();
(gdb) p first
$1 = (circle *) 0x3d24b0
(gdb) p *$
$2 = {start = 0x3d25e0}
(gdb) p $.start
$3 = (node *) 0x3d25e0
(gdb) p *$
$4 = {data = 1, next = 0x3d2770, prev = 0x3d2630}
(gdb) p $.next
$5 = (node *) 0x3d2770
(gdb) p *$
$6 = {data = 1, next = 0x3d2748, prev = 0x411c23}
(gdb) p *$->next
$7 = {data = 2, next = 0x3d2720, prev = 0x3d2770}
(gdb) p *$->next
$8 = {data = 3, next = 0x3d26f8, prev = 0x3d2748}
(gdb) p *$->next
$9 = {data = 4, next = 0x3d26d0, prev = 0x3d2720}
(gdb) p *$->prev
$10 = {data = 3, next = 0x3d26f8, prev = 0x3d2748}
(gdb) p *$->next
$11 = {data = 4, next = 0x3d26d0, prev = 0x3d2720}
(gdb) p *$->next
$12 = {data = 5, next = 0x3d26a8, prev = 0x3d26f8}
(gdb) p *$->next
$13 = {data = 6, next = 0x3d2680, prev = 0x3d26d0}
(gdb) p *$->next
$14 = {data = 7, next = 0x3d2658, prev = 0x3d26a8}
(gdb) p *$->next
$15 = {data = 8, next = 0xbaadf00d, prev = 0x3d2680}
(gdb) p *$->next
$16 = {data = 1768763235, next = 0x3377676e, prev = 0x2e332f32}
(gdb) p *$->next
Cannot access memory at address 0x3377676e
(gdb)
It looks like your loop was created correctly up until the element with data 8.
Looking at your code again, I would guess that that is because of this:
Code:
size = v.size();
size--;
//Insert Data
for(int i=0; i<size-1; i++)
You're not looping as far as maybe you could. With 10 elements in v, the loop executes with i from 0 to 7, inclusive.
Also, don't forget to terminate the last link with pointers to NULL or to the list's head. [/edit]