<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>circular linked list java - Wikitechy</title>
	<atom:link href="https://www.wikitechy.com/interview-questions/tag/circular-linked-list-java/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.wikitechy.com/interview-questions/tag/circular-linked-list-java/</link>
	<description>Interview Questions</description>
	<lastBuildDate>Mon, 13 Sep 2021 06:53:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://www.wikitechy.com/interview-questions/wp-content/uploads/2025/10/cropped-wikitechy-icon-32x32.png</url>
	<title>circular linked list java - Wikitechy</title>
	<link>https://www.wikitechy.com/interview-questions/tag/circular-linked-list-java/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Java Program to reverse a Linked List ?</title>
		<link>https://www.wikitechy.com/interview-questions/java/java-program-to-reverse-a-linked-list/</link>
					<comments>https://www.wikitechy.com/interview-questions/java/java-program-to-reverse-a-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Wed, 14 Jul 2021 00:03:25 +0000</pubDate>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[Applied Materials interview questions and answers]]></category>
		<category><![CDATA[Atos interview questions and answers]]></category>
		<category><![CDATA[Capgemini interview questions and answers]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[CGI Group Inc interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[Ciena Corporation interview questions and answers]]></category>
		<category><![CDATA[circular linked list java]]></category>
		<category><![CDATA[Collabera Technologies interview questions and answers]]></category>
		<category><![CDATA[compro technologies interview questions and answers]]></category>
		<category><![CDATA[create linked list java]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[doubly linked list java]]></category>
		<category><![CDATA[FIS Global Business Solutions India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[how to implement linked list in java]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[Infosys Technologies interview questions and answers]]></category>
		<category><![CDATA[javascript linked list]]></category>
		<category><![CDATA[L&T Infotech interview questions and answers]]></category>
		<category><![CDATA[linked list class in java]]></category>
		<category><![CDATA[linked list data structure in java]]></category>
		<category><![CDATA[linked list implementation in java]]></category>
		<category><![CDATA[linked list implementation in java source code]]></category>
		<category><![CDATA[linked list java code]]></category>
		<category><![CDATA[linked list java tutorial]]></category>
		<category><![CDATA[linked list program in java]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[PeopleStrong interview questions and answers]]></category>
		<category><![CDATA[Persistent Systems interview questions and answers]]></category>
		<category><![CDATA[RBS India De interview questions and answers]]></category>
		<category><![CDATA[Reliance Industries Ltd interview questions and answers]]></category>
		<category><![CDATA[reverse linked list java]]></category>
		<category><![CDATA[SAP Labs India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[singly linked list java]]></category>
		<category><![CDATA[sort linked list java]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[UnitedHealth Group interview questions and answers]]></category>
		<category><![CDATA[Virtusa Consulting Services Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Wells Fargo interview questions and answers]]></category>
		<category><![CDATA[Wipro Infotech interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=666</guid>

					<description><![CDATA[Answer : A Linked list contains two things data and the address of the node each node....]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="java-program-to-reverse-a-linked-list" class="color-pink" style="text-align: justify;">Java Program to reverse a Linked List ?</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>A <a href="https://www.wikitechy.com/technology/quicksort-doubly-linked-list-2/" target="_blank" rel="noopener">Linked list</a> contains two things data and the address of the node each node is linked to the next node.</li>
<li>There can be two solution to reverse a linked list in java.
<ul>
<li><a href="https://www.wikitechy.com/technology/iterative-quick-sort/" target="_blank" rel="noopener">Iterative</a></li>
<li><a href="https://www.wikitechy.com/technology/c-algorithm-write-recursive-function-print-reverse-linked-list/" target="_blank" rel="noopener">Recursive</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="iterative" class="color-purple">Iterative</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Here we have three nodes i.e previousNode, currentNode and nextNode</li>
<li>When currentNode is starting node, then previousNode will be null</li>
<li>Assign currentNode.next to previousNode to reverse the link.</li>
<li>In each iteration move currentNode and previousNode by 1 node.</li>
</ul>
</div>
</div>
<div class="text-center row" style="text-align: justify;">
<div class="col-sm-12">
<div id="bsa-zone_1590522538159-8_123456"></div>
</div>
</div>
<div class="ImageContent">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/java/iterative-method-linked-list.gif" alt=" data- linked-list" /></div>
<div>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-java code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-java code-embed-code">public static Node reverseLinkedList(Node currentNode)<br/>	{<br/>		// For first node, previousNode will be null<br/>		Node previousNode=null;<br/>		Node nextNode;<br/>		while(currentNode!=null)<br/>		{<br/>			nextNode=currentNode.next;<br/>			// reversing the link<br/>			currentNode.next=previousNode;<br/>			// moving currentNode and previousNode by 1 node<br/>			previousNode=currentNode;<br/>			currentNode=nextNode;<br/>		}<br/>		return previousNode;<br/>	}</code></pre> </div>
<h2 id="sample-code-in-java" class="color-pink" style="text-align: justify;">Sample Code in Java:</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-java code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-java code-embed-code">public class LinkedList{<br/> <br/>	private Node head;<br/> <br/>	private static class Node {<br/>		private int value;<br/>		private Node next;<br/> <br/>		Node(int value) {<br/>			this.value = value;<br/> <br/>		}<br/>	}<br/> <br/>	public void addToTheLast(Node node) {<br/> <br/>		if (head == null) {<br/>			head = node;<br/>		} else {<br/>			Node temp = head;<br/>			while (temp.next != null)<br/>				temp = temp.next;<br/> <br/>			temp.next = node;<br/>		}<br/>	}<br/> <br/> <br/>	public void printList(Node head) {<br/>		Node temp = head;<br/>		while (temp != null) {<br/>			System.out.format(&quot;%d &quot;, temp.value);<br/>			temp = temp.next;<br/>		}<br/>		System.out.println();<br/>	}<br/> <br/>	// Reverse linkedlist using this function <br/>	public static Node reverseLinkedList(Node currentNode)<br/>	{<br/>		// For first node, previousNode will be null<br/>		Node previousNode=null;<br/>		Node nextNode;<br/>		while(currentNode!=null)<br/>		{<br/>			nextNode=currentNode.next;<br/>			// reversing the link<br/>			currentNode.next=previousNode;<br/>			// moving currentNode and previousNode by 1 node<br/>			previousNode=currentNode;<br/>			currentNode=nextNode;<br/>		}<br/>		return previousNode;<br/>	}<br/> <br/>	public static void main(String[] args) {<br/>		LinkedList list = new LinkedList();<br/>		// Creating a linked list<br/>		Node head=new Node(5);<br/>		list.addToTheLast(head);<br/>		list.addToTheLast(new Node(6));<br/>		list.addToTheLast(new Node(7));<br/>		list.addToTheLast(new Node(1));<br/>		list.addToTheLast(new Node(2));<br/> <br/>		list.printList(head);<br/>		//Reversing LinkedList<br/>		Node reverseHead=reverseLinkedList(head);<br/>		System.out.println(&quot;After reversing&quot;);<br/>		list.printList(reverseHead);<br/> <br/>	}<br/> <br/>}</code></pre> </div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output" class="color-pink">Output :</h2>
</div>
</div>
<div class="Output">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs" data-lang=""><span class="nt">5 6 7 1 2 
After reversing
2 1 7 6 5</span></code></pre>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="recursive-method" class="color-purple">Recursive Method:</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Divide the list in two parts – first node and rest of the linked list.</li>
<li>Call reverse for the rest of the linked list.</li>
<li>Link rest to first.</li>
<li>Fix head pointer</li>
</ul>
</div>
</div>
<div class="ImageContent">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/java/reverse-linked-list-in-java.jpg" alt=" data- linked-list" /></div>
</div>
</figure>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/java/java-program-to-reverse-a-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to detect a cycle in a linked list ?</title>
		<link>https://www.wikitechy.com/interview-questions/data-structure/how-to-detect-a-cycle-in-a-linked-list/</link>
					<comments>https://www.wikitechy.com/interview-questions/data-structure/how-to-detect-a-cycle-in-a-linked-list/#respond</comments>
		
		<dc:creator><![CDATA[Editor]]></dc:creator>
		<pubDate>Tue, 13 Jul 2021 16:48:05 +0000</pubDate>
				<category><![CDATA[Data Structure]]></category>
		<category><![CDATA[Accenture interview questions and answers]]></category>
		<category><![CDATA[Altimetrik India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Applied Materials interview questions and answers]]></category>
		<category><![CDATA[Bharti Airtel interview questions and answers]]></category>
		<category><![CDATA[BMC Software interview questions and answers]]></category>
		<category><![CDATA[Capgemini interview questions and answers]]></category>
		<category><![CDATA[CASTING NETWORKS INDIA PVT LIMITED interview questions and answers]]></category>
		<category><![CDATA[CGI Group Inc interview questions and answers]]></category>
		<category><![CDATA[Chetu interview questions and answers]]></category>
		<category><![CDATA[Ciena Corporation interview questions and answers]]></category>
		<category><![CDATA[circular linked list java]]></category>
		<category><![CDATA[Collabera Te interview questions and answers]]></category>
		<category><![CDATA[Comodo India Interview Questions and Answers]]></category>
		<category><![CDATA[cycle detection linked list]]></category>
		<category><![CDATA[cycle detection solution]]></category>
		<category><![CDATA[cycle detection solution c++]]></category>
		<category><![CDATA[Dell International Services India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[find cycle in linked list]]></category>
		<category><![CDATA[find length of loop in linked list]]></category>
		<category><![CDATA[find loop in linked list]]></category>
		<category><![CDATA[find start of loop in linked list]]></category>
		<category><![CDATA[Flipkart interview questions and answers]]></category>
		<category><![CDATA[floyd's cycle detection algorithm]]></category>
		<category><![CDATA[floyd's cycle finding algorithm]]></category>
		<category><![CDATA[floyd's cycle-finding algorithm c++]]></category>
		<category><![CDATA[Genpact interview questions and answers]]></category>
		<category><![CDATA[given a linked list]]></category>
		<category><![CDATA[Globallogic India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[IBM interview questions and answers]]></category>
		<category><![CDATA[Indecomm Global Services interview questions and answers]]></category>
		<category><![CDATA[leetcode sort linked list]]></category>
		<category><![CDATA[link cycle]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[linked list cycle]]></category>
		<category><![CDATA[linked list in data structure]]></category>
		<category><![CDATA[linked lists detect a cycle]]></category>
		<category><![CDATA[list cycle]]></category>
		<category><![CDATA[Mphasis interview questions and answers]]></category>
		<category><![CDATA[n'th node from end of linked list]]></category>
		<category><![CDATA[nested loops java]]></category>
		<category><![CDATA[NetApp interview questions and answers]]></category>
		<category><![CDATA[Oracle Corporation interview questions and answers]]></category>
		<category><![CDATA[python linked list cycle]]></category>
		<category><![CDATA[remove loop in linked list]]></category>
		<category><![CDATA[return the node where the cycle begins. if there is no cycle]]></category>
		<category><![CDATA[SAP Labs India Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Sapient Consulting Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Tech Mahindra interview questions and answers]]></category>
		<category><![CDATA[Tracxn Technologies Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[UnitedHealth Group interview questions and answers]]></category>
		<category><![CDATA[what is linked list in data structure]]></category>
		<category><![CDATA[Wipro Infotech interview questions and answers]]></category>
		<category><![CDATA[WM Global Technology Services India Pvt.Ltd Limited (WMGTS) interview questions and answers]]></category>
		<category><![CDATA[Xoriant Solutions Pvt Ltd interview questions and answers]]></category>
		<category><![CDATA[Yodlee Infotech Pvt Ltd interview questions and answers]]></category>
		<guid isPermaLink="false">https://www.wikitechy.com/interview-questions/?p=497</guid>

					<description><![CDATA[Answer : A linked list is said to contain a cycle ...]]></description>
										<content:encoded><![CDATA[<div class="TextHeading">
<div class="hddn">
<h2 id="how-to-detect-a-cycle-in-a-linked-list" class="color-pink" style="text-align: justify;">How to detect a cycle in a linked list ?</h2>
<ul style="text-align: justify;">
<li>A <a href="https://www.wikitechy.com/technology/circular-linked-list-introduction-applications/" target="_blank" rel="noopener">linked list</a> is said to contain a cycle if any node is visited more than once.</li>
</ul>
</div>
</div>
<div class="ImageContent" style="text-align: justify;">
<div class="hddn"><img decoding="async" class="img-responsive center-block aligncenter" src="https://cdn.wikitechy.com/interview-questions/data-structure/how-to-detect-a-cycle-in-a-linked-list.png" alt="How do you detect a cycle in a linked list" /></div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="method-1-using-hashing" class="color-green">Method 1 – Using Hashing</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Traverse the given list.</li>
<li>Insert each encountered node into a <a href="https://www.wikitechy.com/tutorials/java/java-hash-table" target="_blank" rel="noopener">hash table</a>.</li>
<li>If the current already present ,that means the cycle is present or not.</li>
</ul>
</div>
</div>
<div class="TextHeading">
<div class="hddn">
<h2 id="sample-code" class="color-blue" style="text-align: justify;">Sample code</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-java code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-java code-embed-code">#include <iostream><br/>#include <unordered_set><br/>using namespace std;<br/><br/>// Data Structure to store a linked list node<br/>struct Node<br/>{<br/>    int dt;<br/>    Node* next;<br/>};<br/><br/>// Helper function to create a new node with the given data and<br/>// pushes it onto the front of the list<br/>void push(Node*& headRef, int dt)<br/>{<br/>    // create a new linked list node from heap<br/>    Node* newNode = new Node;<br/><br/>    newNode->dt = dt;<br/>    newNode->next = headRef;<br/>    headRef = newNode;<br/>}<br/><br/>// Function to detect Cycle in a linked list using Hashing<br/>bool detectcyc(Node *head)<br/>{<br/>    Node *current = head;<br/>    unordered_set<Node*> set;<br/><br/>    // traverse the list<br/>    while (current)<br/>    {<br/>        // return false if we already have seen this node before<br/>        if (set.find(current) != set.end())<br/>            return true;<br/><br/>        // insert current node into the set<br/>        set.insert(current);<br/><br/>        // move to the next node<br/>        current = current->next;<br/>    }<br/><br/>    // we reach here if list does not contain any cycle<br/>    return false;<br/>}<br/><br/>// Detect Cycle in a linked list<br/>int main()<br/>{<br/>    // input keys<br/>    int k[] = { 1, 2, 3, 4, 5 };<br/>    int n = sizeof(k) / sizeof(k[0]);<br/><br/>    Node* head = nullptr;<br/>    for (int i = n - 1; i >= 0; i--)<br/>        push(head, k[i]);<br/><br/>    // insert cycle<br/>    head->next->next->next->next->next = head->next->next;<br/><br/>    if (detectcyc(head))<br/>        cout << &quot;Cycle Found&quot;;<br/>    else<br/>        cout << &quot;No Cycle Found&quot;;<br/><br/>    return 0;<br/>}</code></pre> </div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output" class="color-blue">Output</h2>
</div>
</div>
<div class="Output" style="text-align: justify;">
<div class="hddn">
<figure class="highlight">
<pre><code class="hljs" data-lang=""><span class="nt">Cycle Found
</span></code></pre>
</figure>
</div>
</div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="method-2-floyds-cycle-detection-algorithm" class="color-green">Method 2 – Floyd’s Cycle Detection Algorithm</h2>
</div>
</div>
<div class="Content" style="text-align: justify;">
<div class="hddn">
<ul>
<li>Use two pointers, which move through the sequence at different speed.</li>
<li>The fast <a href="https://www.wikitechy.com/tutorials/c++/c++-pointers-to-structure" target="_blank" rel="noopener">pointer</a> moves twice as quickly as the slow pointer.</li>
<li>Here the distance between the two pointers increased by 1 at each step.</li>
<li>If these <a href="https://www.wikitechy.com/tutorials/c++/pointer-to-array-in-c++" target="_blank" rel="noopener">pointers</a> meet at same node then there is a loop else <a href="https://www.wikitechy.com/technology/sorted-insert-circular-linked-list-2/" target="_blank" rel="noopener">linked list</a> doesn’t have loop.</li>
</ul>
</div>
</div>
<div class="TextHeading">
<div class="hddn">
<h2 id="sample-code-2" class="color-blue" style="text-align: justify;">Sample Code</h2>
<div class="code-embed-wrapper"> <div class="code-embed-infos"> </div> <pre class="language-java code-embed-pre line-numbers"  data-start="1" data-line-offset="0"><code class="language-java code-embed-code">#include <iostream><br/>#include <unordered_set><br/>using namespace std;<br/><br/>// Data Structure to store a linked list node<br/>struct Node<br/>{<br/>    int dt;<br/>    Node* next;<br/>};<br/><br/>// Helper function to create a new node with the given data and<br/>// pushes it onto the front of the list<br/>void push(Node*& headRef, int dt)<br/>{<br/>    // create a new linked list node from heap<br/>    Node* nNode = new Node;<br/><br/>    nNode->dt = dt;<br/>    nNode->next = headRef;<br/>    headRef = nNode;<br/>}<br/><br/>// Function to detect Cycle in a linked list using<br/>// Floyd’s Cycle Detection Algorithm<br/>bool dcycle(Node *head)<br/>{<br/>    // take two pointers - slow and fast<br/>    Node *slow = head, *fast = head;<br/><br/>    while (fast && fast->next)<br/>    {<br/>        // move slow by one pointer<br/>        slow = slow->next;<br/><br/>        // move fast by two pointers<br/>        fast = fast->next->next;<br/><br/>        // if they meet any any node, linked list contains a cycle<br/>        if (slow == fast)<br/>            return true;<br/>    }<br/><br/>    // we reach here if slow & fast pointer do not meet<br/>    return false;<br/>}<br/><br/>// Detect Cycle in a linked list using Floyd’s Cycle Detection Algorithm<br/>int main()<br/>{<br/>    // input keys<br/>    int k[] = { 1, 2, 3, 4, 5 };<br/>    int n = sizeof(k) / sizeof(k[0]);<br/><br/>    Node* head = nullptr;<br/>    for (int i = n - 1; i >= 0; i--)<br/>        push(head, k[i]);<br/><br/>    // insert cycle<br/>    head->next->next->next->next->next = head->next->next;<br/><br/>    if (dcycle(head))<br/>        cout << &quot;Cycle Found&quot;;<br/>    else<br/>        cout << &quot;No Cycle Found&quot;;<br/><br/>    return 0;<br/>}</code></pre> </div>
<div class="TextHeading" style="text-align: justify;">
<div class="hddn">
<h2 id="output-2" class="color-blue">Output</h2>
</div>
</div>
<div class="Output">
<div class="hddn">
<figure class="highlight" style="text-align: justify;">
<pre><code class="hljs" data-lang=""><span class="nt">Cycle Found</span></code></pre>
</figure>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.wikitechy.com/interview-questions/data-structure/how-to-detect-a-cycle-in-a-linked-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
