Hack Forums
[Java] Circular Linked Lists - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Circular Linked Lists (/showthread.php?tid=5760832)



Circular Linked Lists - JakeDarkblade - Nov 30, 2017

This is the code i've come up with to return a String containing the items of all the nodes in the list separated by commas. But this code doesn't work with a linked list that is circular that connects back to the head node.


RE: Circular Linked Lists - GoodVibes - Nov 30, 2017

i really wish i could help you, but unfortunately i don't know much about programming or java in general.

good luck in figuring this out though.

wow.

ok, so what i would do is on the second current!=null check i'd also checck if currentl also doesn't equal head
so like
Code
if(current != null && !current.equals(head))
for the second if(current != null) check

that should do it for you friend.

only wrote out all that code bc i'm guessing your new bc this was relatively simple problem, i'm just very coked out right now so i hope this helps.

cheers.


RE: Circular Linked Lists - JakeDarkblade - Nov 30, 2017

(Nov 30, 2017 05:56 PM)GoodVibes Wrote:  i really wish i could help you, but unfortunately i don't know much about programming or java in general.

good luck in figuring this out though.

wow.

ok, so what i would do is on the second current!=null check i'd also checck if currentl also doesn't equal head
so like
Code
if(current != null && !current.equals(head))
for the second if(current != null) check

that should do it for you friend.

only wrote out all that code bc i'm guessing your new bc this was relatively simple problem, i'm just very coked out right now so i hope this helps.

cheers.

Thanks for that brother and yeah i'm new


RE: Circular Linked Lists - Sheeple - Nov 30, 2017

omg I just started learning linked listss in class
mind
blown

I need help on my HW but my professor didn't provide me a main.java even tho it says he did and to use it to write the code soooooooooooooooooooooooooooooo


RE: Circular Linked Lists - GenericSkid - Nov 30, 2017

Its not really a hard concept to understand:
[Image: wmoede.png]

In this picture we have two instances of Node. The class node looks like this:

PHP Code

<?php 
class Node {
 
   Node next;
 
   Node prev;
} 

To construct a list of a single element:
PHP Code

<?php 
Node n 
= new Node();
// forward connections (green)
n.next = n;
// backward connections (red)
n.prev = n; 

Now if we want a list of two elements:
PHP Code

<?php 
Node n1 
= new Node();
Node n2 = new Node();
// forward connections (green)
n1.next = n2;
n2.next = n1;
// backward connections (red)
n1.prev = n2;
n2.prev = n1; 

Obviously you will not want to do this manually so you would have methods for adding to the list (and handling edge cases). But as long as the links follow the pattern in the image above you have yourself a circular linked list.


RE: Circular Linked Lists - matt - Dec 1, 2017

Check out my latest post in the same subforum I just talked about doubly circular linked lists and you may use it for REFERENCE
If this is for school I do NOT give you permission to use this however you may study it and take concepts from it to create your own material


RE: Circular Linked Lists - GoodVibes - Dec 1, 2017

(Dec 1, 2017 06:26 AM)Midnight Blue™ Wrote:  Check out my latest post in the same subforum I just talked about doubly circular linked lists and you may use it for REFERENCE
If this is for school I do NOT give you permission to use this however you may study it and take concepts from it to create your own material

hi,you can call me young turbo
no one cares if u give permission or not if u put it on the internet and he wants to steal it he will lol

god blessings,
xoxo

young turbo


RE: Circular Linked Lists - JakeDarkblade - Dec 1, 2017

(Dec 1, 2017 06:26 AM)Midnight Blue™ Wrote:  Check out my latest post in the same subforum I just talked about doubly circular linked lists and you may use it for REFERENCE
If this is for school I do NOT give you permission to use this however you may study it and take concepts from it to create your own material

Thanks brother I’ll have a look later.


RE: Circular Linked Lists - matt - Dec 1, 2017

(Dec 1, 2017 01:08 PM)GoodVibes Wrote:  hi,you can call me young turbo
no one cares if u give permission or not if u put it on the internet and he wants to steal it he will lol

god blessings,
xoxo

young turbo

His fault if he gets caught cheating, lots of algorithms now a days that check for plagiarized work.