linked lists in java are so much easier than in C++

notfred

Lifer
Feb 12, 2001
38,241
4
0
I have to write a doubly linked list in java for this data structures class. I have about 6 or 8 hours of java programming experience, and my program already is compiling and running (it's not complete yet...)

I remeber when I did this in C++ it was a complete bitch to get working, and I've spent maybe 2 hours in a brand new language and it's already mostly working.
 

Supermercado

Diamond Member
Jan 18, 2002
5,893
0
76
How so? I just started C++ after 3 semesters of Java and one of C, but wouldn't the implementation be more or less the same? Create a class for each node and one for the linked list?
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: notfred
I have to write a doubly linked list in java for this data structures class. I have about 6 or 8 hours of java programming experience, and my program already is compiling and running (it's not complete yet...)

I remeber when I did this in C++ it was a complete bitch to get working, and I've spent maybe 2 hours in a brand new language and it's already mostly working.

writiing linked lists is like learning to add, it only gets harder from there on out.
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: SuperCommando
How so? I just started C++ after 3 semesters of Java and one of C, but wouldn't the implementation be more or less the same? Create a class for each node and one for the linked list?

most beggenir programmers have a tough time with pointers and memory allocation and deallocation, java makes all that alot easier at the cost of performance.
 

Supermercado

Diamond Member
Jan 18, 2002
5,893
0
76
Originally posted by: Ameesh
Originally posted by: SuperCommando
How so? I just started C++ after 3 semesters of Java and one of C, but wouldn't the implementation be more or less the same? Create a class for each node and one for the linked list?

most beggenir programmers have a tough time with pointers and memory allocation and deallocation, java makes all that alot easier at the cost of performance.
I guess that makes sense. Yeah, I'm still a noob at C++. Thank you for your help the other day with my static variables, BTW.

 

Yomicron

Golden Member
Mar 5, 2002
1,735
1
81
Originally posted by: Ameesh
Originally posted by: SuperCommando
How so? I just started C++ after 3 semesters of Java and one of C, but wouldn't the implementation be more or less the same? Create a class for each node and one for the linked list?

most beggenir programmers have a tough time with pointers and memory allocation and deallocation, java makes all that alot easier at the cost of performance.

and Smalltalk makes it even easier, at the cost of even more performance, but coding in Smalltalk is so cool :D
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: SuperCommando
How so? I just started C++ after 3 semesters of Java and one of C, but wouldn't the implementation be more or less the same? Create a class for each node and one for the linked list?

Like Ameesh said, you don't worry about keeping track of your pointers and memory allocation in java.

And, regarding what Ameesh said about "learning to add"

I'll likely do a couple addition problems, then get to use a calculator from there on out, same with multiplication and division...

They wrote all these libraries for a reason :)
 

mchammer187

Diamond Member
Nov 26, 2000
9,114
0
76
Originally posted by: brtspears2
Linked lists is the reason I quit being a CS major and became an EE major.

I am EE and i deal with linked lists all the time

i luv coding them up now :D

they are a pain in the ass in regular C

linked list in java is easier because there is no use of the dereferce operator *

because everything you create is inherently a pointer except for primitive types i believe

i am starting to like java a lot now even though i've only had about 9 hrs of java class so far

my teacher told me C# is even better i'd like to learn that but I dont think they teach it here

 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: notfred
Originally posted by: SuperCommando
How so? I just started C++ after 3 semesters of Java and one of C, but wouldn't the implementation be more or less the same? Create a class for each node and one for the linked list?

Like Ameesh said, you don't worry about keeping track of your pointers and memory allocation in java.

And, regarding what Ameesh said about "learning to add"

I'll likely do a couple addition problems, then get to use a calculator from there on out, same with multiplication and division...

They wrote all these libraries for a reason :)

what happens when their isnt a library for you to use?
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
linked list in java is easier because there is no use of the dereferce operator *

its statments like this that make me hate the universities that only teach java. or teach java before c/c++
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: Ameesh
Originally posted by: notfred
Originally posted by: SuperCommando
How so? I just started C++ after 3 semesters of Java and one of C, but wouldn't the implementation be more or less the same? Create a class for each node and one for the linked list?

Like Ameesh said, you don't worry about keeping track of your pointers and memory allocation in java.

And, regarding what Ameesh said about "learning to add"

I'll likely do a couple addition problems, then get to use a calculator from there on out, same with multiplication and division...

They wrote all these libraries for a reason :)

what happens when their isnt a library for you to use?

Then I write something from scratch, which is why I'm learning all this stuff. However, if I can come up with a new type of data structure that no one's ever written a library for, I can probably come up with the code to do it. Just because I wont normally write linked lists from scratch (or binary trees, or whatever) doesn't mean that I can't or won't ever do it.
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: notfred
Originally posted by: Ameesh
Originally posted by: notfred
Originally posted by: SuperCommando
How so? I just started C++ after 3 semesters of Java and one of C, but wouldn't the implementation be more or less the same? Create a class for each node and one for the linked list?

Like Ameesh said, you don't worry about keeping track of your pointers and memory allocation in java.

And, regarding what Ameesh said about "learning to add"

I'll likely do a couple addition problems, then get to use a calculator from there on out, same with multiplication and division...

They wrote all these libraries for a reason :)

what happens when their isnt a library for you to use?

Then I write something from scratch, which is why I'm learning all this stuff. However, if I can come up with a new type of data structure that no one's ever written a library for, I can probably come up with the code to do it. Just because I wont normally write linked lists from scratch (or binary trees, or whatever) doesn't mean that I can't or won't ever do it.

if you dont do it regualrly, its hard to do period. like math the only way to get better is to actually do the problems.

and the point i was making about linked lists was that its only a very basic data structure, in production code people use qudratic hastables, avl trees, skip lists, patricia trees, heaps, ASMs, graphs, etc., in their everday work. if you are struggling with a linked list in c++ i suggest you take a look at it again and get comfortable with it.

those are just the data structures, dont get me started on algorothims because they get harder and harder, look up a subject called dynamic programming (that is tough stuff to get your mind around)

(just tryin to give you the best advice i can, im not tryin to be an ass or anything)


 

notfred

Lifer
Feb 12, 2001
38,241
4
0
When did I say I was struggling with linked lists? I've been writing java for 6 hours and I have a functioning list (only 1 or2 of those hours was spent on the list program), I think that's pretty good. Also, the title of the thread makes reference to how easy this was, not how difficult it was :)
 

kherman

Golden Member
Jul 21, 2002
1,511
0
0
I'm a software engineer in industry. The concepts are the most important aspect when you are a student. It doesn't matter what language you implement something in as long as it works properly. if you know one OO language, learning a second is a piece of cake. Anyone can learn a new language.

Just don't cheat on your HW, the concepts are what is important.

I'd rather see students use C++ though, becauseh te concepts behiund how pointers work is VERY important. Beyond that, even use assembly once in a while.
 

charrison

Lifer
Oct 13, 1999
17,033
1
81
Originally posted by: notfred
I have to write a doubly linked list in java for this data structures class. I have about 6 or 8 hours of java programming experience, and my program already is compiling and running (it's not complete yet...)

I remeber when I did this in C++ it was a complete bitch to get working, and I've spent maybe 2 hours in a brand new language and it's already mostly working.

vector<classname> vectorofclasses;

Yup it is tough to write a linked list in c++.

Now go do you homework and learn how to do your own memory management. It is a vital skill to learn, as you will not always be in language of your choice.
 

Jzero

Lifer
Oct 10, 1999
18,834
1
0
I enjoy not having to reinvent the wheel everytime I start a new project. I enjoy not having to do my own garbage collection. I'm not a hardcore programmer. Java is perfect for me :)

I can do the same thing Java much faster than I could in C++. A lot of production-level stuff is now in J2EE, anyway. My company is hardly even looking for C++ programmers anymore. The codebase of our latest version is entirely J2EE....
YMMV, but Java sure works for me ;)
 

mchammer187

Diamond Member
Nov 26, 2000
9,114
0
76
Originally posted by: charrison
Originally posted by: Ameesh
linked list in java is easier because there is no use of the dereferce operator *

its statments like this that make me hate the universities that only teach java. or teach java before c/c++

Well said.

Am I wrong (I had years of C++) 2 college 2 in highschool which I equate to 1

most people have problems with pointers and linked list because they do not know when to deference

memory allocation is not that hard new & delete it and its way better than that malloc crap you use is C

I am a java n00b though and it is easy as pie from what i've learned so far

people that take java think that there are no pointers just because they dont have int *i or something like that

C/C++ also lets you code up complete crap and it will still compile which will lead to dozens of seg faults if you are not careful
whereas Java would not

but IMO once you master C++ everything else is easy

I just wish they taught us to program with exceptions in C/ C++ because that would have made learning it a lot easier in C++
 

mchammer187

Diamond Member
Nov 26, 2000
9,114
0
76
Originally posted by: Jzero
I enjoy not having to reinvent the wheel everytime I start a new project. I enjoy not having to do my own garbage collection. I'm not a hardcore programmer. Java is perfect for me :)

I can do the same thing Java much faster than I could in C++. A lot of production-level stuff is now in J2EE, anyway. My company is hardly even looking for C++ programmers anymore. The codebase of our latest version is entirely J2EE....
YMMV, but Java sure works for me ;)

that maybe fine but isnt Java inherently slower than C/C++ because it must be run on the JVM?
 

Electric Amish

Elite Member
Oct 11, 1999
23,578
1
0
I LOVE linked lists!!! :)

My friend and I wrote a Chinese Checkers game where the board positions were constructed using node with 6 links each! :)

Coding that game was a blast! :D

amish
 

bUnMaNGo

Senior member
Feb 9, 2000
964
0
0
Originally posted by: charrison
Originally posted by: notfred
I have to write a doubly linked list in java for this data structures class. I have about 6 or 8 hours of java programming experience, and my program already is compiling and running (it's not complete yet...)

I remeber when I did this in C++ it was a complete bitch to get working, and I've spent maybe 2 hours in a brand new language and it's already mostly working.

vector<classname> vectorofclasses;

Yup it is tough to write a linked list in c++.

Now go do you homework and learn how to do your own memory management. It is a vital skill to learn, as you will not always be in language of your choice.

rofl... yay for STL :) then again in Java, you can use java.util.LinkedList and do List list; can't you? hehe so I guess it technically would be easier in Java :)
 

Jzero

Lifer
Oct 10, 1999
18,834
1
0
Originally posted by: mchammer187
Originally posted by: Jzero
I enjoy not having to reinvent the wheel everytime I start a new project. I enjoy not having to do my own garbage collection. I'm not a hardcore programmer. Java is perfect for me :)

I can do the same thing Java much faster than I could in C++. A lot of production-level stuff is now in J2EE, anyway. My company is hardly even looking for C++ programmers anymore. The codebase of our latest version is entirely J2EE....
YMMV, but Java sure works for me ;)

that maybe fine but isnt Java inherently slower than C/C++ because it must be run on the JVM?

As with any interpreted language, it's going to be theoretically slower than any strictly compiled language. These days, though, the VM is tuned well enough, and the computers themselves are fast enough that Java works. Currently, some of the major projects that I use, Tripwire 3 and Cyclone Interchange, for instance are both Java. They run just as fast as comparable apps. My comany's software is also amazingly fast and robust. The portability for which Java was designed ensures that this software works in any environment so long as they have a VM available to them. Our old C++ version only ran in Win32. Now we can support almost any environment. It's a beautiful thing. We no longer have to give up prospective non Windows clients simply b/c we don't have the resources to develop ports of the software.

The slowness of interpreting byte code isn't the same issue it was even 2 years ago.
 

gopunk

Lifer
Jul 7, 2001
29,239
2
0
Originally posted by: Ameesh
linked list in java is easier because there is no use of the dereferce operator *

its statments like this that make me hate the universities that only teach java. or teach java before c/c++

yea, but what if they taught C#? ;)