SlideShare a Scribd company logo
SOURCE CODE:
import java.util.Iterator;
public class CircularLinkedList implements Iterable {
Node head , tail;
int size;
CircularLinkedList() {
head = null;
tail = null;
size = 0;
}
public boolean add(E e) {
Node ele = new Node(e);
ele.next = head;
if(head == null)
{
head = ele;
ele.next = head;
tail = head;
}
else
{
tail.next = ele;
tail = ele;
}
size++;
return true;
}
public boolean add(int index, E e){
Node ele = new Node(e);
Node ptr = head;
index = index - 1 ;
for (int i = 1; i < size - 1; i++)
{
if (i == index)
{
Node tmp = ptr.next;
ptr.next = ele;
ele.next = tmp;
break;
}
ptr = ptr.next;
}
size++ ;
return true;
}
private Node getNode(int index ) {
return null;
}
public E remove(int index) {
Node ret;
if (size == 1 && index == 1)
{
ret = head;
head = null;
tail = null;
size = 0;
return ret.getElement();
}
if (index == 1)
{
ret = head;
head = head.next;
tail.next = head;
size--;
return ret.getElement();
}
if (index == size)
{
Node s = head;
Node t = head;
while (s != tail)
{
t = s;
s = s.next;
}
ret = tail;
tail = head;
tail = t;
size --;
return ret.getElement();
}
Node ptr = head;
index = index - 1 ;
for (int i = 1; i < size - 1; i++)
{
if (i == index)
{
Node tmp = ptr.next;
tmp = tmp.next;
ptr.next = tmp;
break;
}
ptr = ptr.next;
}
size-- ;
return ptr.getElement();
}
public String toString()
{
Node current = head;
String result = "";
if(size == 0){
return "";
}
if(size == 1) {
return head.getElement().toString();
}
else{
do{
result = result + current.getElement().toString();
result = result + " ==> ";
current = current.next;
} while(current != head);
}
return result;
}
public Iterator iterator() {
return new ListIterator();
}
private class ListIterator implements Iterator{
Node nextItem;
Node prev;
int index;
@SuppressWarnings("unchecked")
public ListIterator(){
nextItem = (Node) head;
index = 0;
}
public boolean hasNext() {
return size != 0;
}
public E next() {
prev = nextItem;
nextItem = nextItem.next;
index = (index + 1) % size;
return prev.getElement();
}
public void remove() {
int target;
if(nextItem == head) {
target = size - 1;
} else{
target = index - 1;
index--;
}
CircularLinkedList.this.remove(target); //calls the above class
}
}
// Solve the problem in the main method
// The answer of n = 13, k = 2 is
// the 11th person in the ring (index 10)
public static void main(String[] args){
CircularLinkedList l = new CircularLinkedList();
int n=13;
int k=2;
for(int i=1;i<=n;i++)
l.add(Integer.valueOf(i));
int j = 13,i=0;
while(j>0)
{
System.out.println(l.toString());
i = i + k;
if(i>j)
i = k;
l.remove(i);
j--;
}
}
}
OUTPUT:
1 ==> 2 ==> 3 ==> 4 ==> 5 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
1 ==> 3 ==> 4 ==> 5 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 12 ==> 13 ==>
1 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 12 ==> 13 ==>
1 ==> 4 ==> 6 ==> 9 ==> 10 ==> 12 ==> 13 ==>
1 ==> 4 ==> 6 ==> 9 ==> 10 ==> 13 ==>
1 ==> 6 ==> 9 ==> 10 ==> 13 ==>
1 ==> 6 ==> 9 ==> 13 ==>
1 ==> 9 ==> 13 ==>
1 ==> 13 ==>
1
Solution
SOURCE CODE:
import java.util.Iterator;
public class CircularLinkedList implements Iterable {
Node head , tail;
int size;
CircularLinkedList() {
head = null;
tail = null;
size = 0;
}
public boolean add(E e) {
Node ele = new Node(e);
ele.next = head;
if(head == null)
{
head = ele;
ele.next = head;
tail = head;
}
else
{
tail.next = ele;
tail = ele;
}
size++;
return true;
}
public boolean add(int index, E e){
Node ele = new Node(e);
Node ptr = head;
index = index - 1 ;
for (int i = 1; i < size - 1; i++)
{
if (i == index)
{
Node tmp = ptr.next;
ptr.next = ele;
ele.next = tmp;
break;
}
ptr = ptr.next;
}
size++ ;
return true;
}
private Node getNode(int index ) {
return null;
}
public E remove(int index) {
Node ret;
if (size == 1 && index == 1)
{
ret = head;
head = null;
tail = null;
size = 0;
return ret.getElement();
}
if (index == 1)
{
ret = head;
head = head.next;
tail.next = head;
size--;
return ret.getElement();
}
if (index == size)
{
Node s = head;
Node t = head;
while (s != tail)
{
t = s;
s = s.next;
}
ret = tail;
tail = head;
tail = t;
size --;
return ret.getElement();
}
Node ptr = head;
index = index - 1 ;
for (int i = 1; i < size - 1; i++)
{
if (i == index)
{
Node tmp = ptr.next;
tmp = tmp.next;
ptr.next = tmp;
break;
}
ptr = ptr.next;
}
size-- ;
return ptr.getElement();
}
public String toString()
{
Node current = head;
String result = "";
if(size == 0){
return "";
}
if(size == 1) {
return head.getElement().toString();
}
else{
do{
result = result + current.getElement().toString();
result = result + " ==> ";
current = current.next;
} while(current != head);
}
return result;
}
public Iterator iterator() {
return new ListIterator();
}
private class ListIterator implements Iterator{
Node nextItem;
Node prev;
int index;
@SuppressWarnings("unchecked")
public ListIterator(){
nextItem = (Node) head;
index = 0;
}
public boolean hasNext() {
return size != 0;
}
public E next() {
prev = nextItem;
nextItem = nextItem.next;
index = (index + 1) % size;
return prev.getElement();
}
public void remove() {
int target;
if(nextItem == head) {
target = size - 1;
} else{
target = index - 1;
index--;
}
CircularLinkedList.this.remove(target); //calls the above class
}
}
// Solve the problem in the main method
// The answer of n = 13, k = 2 is
// the 11th person in the ring (index 10)
public static void main(String[] args){
CircularLinkedList l = new CircularLinkedList();
int n=13;
int k=2;
for(int i=1;i<=n;i++)
l.add(Integer.valueOf(i));
int j = 13,i=0;
while(j>0)
{
System.out.println(l.toString());
i = i + k;
if(i>j)
i = k;
l.remove(i);
j--;
}
}
}
OUTPUT:
1 ==> 2 ==> 3 ==> 4 ==> 5 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
1 ==> 3 ==> 4 ==> 5 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 12 ==> 13 ==>
1 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 12 ==> 13 ==>
1 ==> 4 ==> 6 ==> 9 ==> 10 ==> 12 ==> 13 ==>
1 ==> 4 ==> 6 ==> 9 ==> 10 ==> 13 ==>
1 ==> 6 ==> 9 ==> 10 ==> 13 ==>
1 ==> 6 ==> 9 ==> 13 ==>
1 ==> 9 ==> 13 ==>
1 ==> 13 ==>
1
Ad

More Related Content

Similar to SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf (20)

i am looking for help on the method AddSorted and the method Copy only.pdf
i am looking for help on the method AddSorted and the method Copy only.pdfi am looking for help on the method AddSorted and the method Copy only.pdf
i am looking for help on the method AddSorted and the method Copy only.pdf
sonunotwani
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
mail931892
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
package ex2- public class Exercise2-E- { private static class N.pdf
package ex2- public class Exercise2-E- {        private static class N.pdfpackage ex2- public class Exercise2-E- {        private static class N.pdf
package ex2- public class Exercise2-E- { private static class N.pdf
arcellzone
 
Submit1) Java Files2) Doc file with the following contents.pdf
Submit1) Java Files2) Doc file with the following contents.pdfSubmit1) Java Files2) Doc file with the following contents.pdf
Submit1) Java Files2) Doc file with the following contents.pdf
akaluza07
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
Chinmay Chauhan
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
mohamed sikander
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
Anaya Zafar
 
using set identitiesSolutionimport java.util.Scanner; c.pdf
using set identitiesSolutionimport java.util.Scanner;  c.pdfusing set identitiesSolutionimport java.util.Scanner;  c.pdf
using set identitiesSolutionimport java.util.Scanner; c.pdf
excellentmobilesabc
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
mckellarhastings
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
DEVTYPE
 
Solve using Java programming language- ----------------------------.pdf
Solve using Java programming language-   ----------------------------.pdfSolve using Java programming language-   ----------------------------.pdf
Solve using Java programming language- ----------------------------.pdf
aksahnan
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Codemotion
 
Data Structures & Algorithms - Lecture 3
Data Structures & Algorithms - Lecture 3Data Structures & Algorithms - Lecture 3
Data Structures & Algorithms - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Create a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfCreate a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdf
mohamednihalshahru
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
21E135MAHIESHWARJ
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
alphaagenciesindia
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
i am looking for help on the method AddSorted and the method Copy only.pdf
i am looking for help on the method AddSorted and the method Copy only.pdfi am looking for help on the method AddSorted and the method Copy only.pdf
i am looking for help on the method AddSorted and the method Copy only.pdf
sonunotwani
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
mail931892
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
package ex2- public class Exercise2-E- { private static class N.pdf
package ex2- public class Exercise2-E- {        private static class N.pdfpackage ex2- public class Exercise2-E- {        private static class N.pdf
package ex2- public class Exercise2-E- { private static class N.pdf
arcellzone
 
Submit1) Java Files2) Doc file with the following contents.pdf
Submit1) Java Files2) Doc file with the following contents.pdfSubmit1) Java Files2) Doc file with the following contents.pdf
Submit1) Java Files2) Doc file with the following contents.pdf
akaluza07
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
Chinmay Chauhan
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
Anaya Zafar
 
using set identitiesSolutionimport java.util.Scanner; c.pdf
using set identitiesSolutionimport java.util.Scanner;  c.pdfusing set identitiesSolutionimport java.util.Scanner;  c.pdf
using set identitiesSolutionimport java.util.Scanner; c.pdf
excellentmobilesabc
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
mckellarhastings
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
annaelctronics
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
DEVTYPE
 
Solve using Java programming language- ----------------------------.pdf
Solve using Java programming language-   ----------------------------.pdfSolve using Java programming language-   ----------------------------.pdf
Solve using Java programming language- ----------------------------.pdf
aksahnan
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Codemotion
 
Create a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfCreate a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdf
mohamednihalshahru
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
alphaagenciesindia
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 

More from arccreation001 (20)

2) In Autocrine signalling, reception of a signal released by the sa.pdf
2) In Autocrine signalling, reception of a signal released by the sa.pdf2) In Autocrine signalling, reception of a signal released by the sa.pdf
2) In Autocrine signalling, reception of a signal released by the sa.pdf
arccreation001
 
Volatility Distillation separates out different .pdf
                     Volatility  Distillation separates out different .pdf                     Volatility  Distillation separates out different .pdf
Volatility Distillation separates out different .pdf
arccreation001
 
The first one has Van der Waals interactions sinc.pdf
                     The first one has Van der Waals interactions sinc.pdf                     The first one has Van der Waals interactions sinc.pdf
The first one has Van der Waals interactions sinc.pdf
arccreation001
 
Supersaturated actually. There is more solvent th.pdf
                     Supersaturated actually. There is more solvent th.pdf                     Supersaturated actually. There is more solvent th.pdf
Supersaturated actually. There is more solvent th.pdf
arccreation001
 
In optics, a virtual image is an image in which t.pdf
                     In optics, a virtual image is an image in which t.pdf                     In optics, a virtual image is an image in which t.pdf
In optics, a virtual image is an image in which t.pdf
arccreation001
 
1) Political orientation and ideas are the main reasons behind count.pdf
1) Political orientation and ideas are the main reasons behind count.pdf1) Political orientation and ideas are the main reasons behind count.pdf
1) Political orientation and ideas are the main reasons behind count.pdf
arccreation001
 
Molarity = moles volume in L Molarity = 0.0342.pdf
                     Molarity = moles  volume in L Molarity = 0.0342.pdf                     Molarity = moles  volume in L Molarity = 0.0342.pdf
Molarity = moles volume in L Molarity = 0.0342.pdf
arccreation001
 
The tracheal system in insects and gills in fishes are both helps th.pdf
The tracheal system in insects and gills in fishes are both helps th.pdfThe tracheal system in insects and gills in fishes are both helps th.pdf
The tracheal system in insects and gills in fishes are both helps th.pdf
arccreation001
 
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdfThe answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
arccreation001
 
The A and B chains of human insulin are cloned in separate plasmids .pdf
The A and B chains of human insulin are cloned in separate plasmids .pdfThe A and B chains of human insulin are cloned in separate plasmids .pdf
The A and B chains of human insulin are cloned in separate plasmids .pdf
arccreation001
 
Question 1How many parameters does a default constructor haveAn.pdf
Question 1How many parameters does a default constructor haveAn.pdfQuestion 1How many parameters does a default constructor haveAn.pdf
Question 1How many parameters does a default constructor haveAn.pdf
arccreation001
 
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdfRio de Janeiro is a city located on Brazils south-east coast. It i.pdf
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
arccreation001
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
arccreation001
 
1.Types of Computer Information SystemsThere are four basic type.pdf
1.Types of Computer Information SystemsThere are four basic type.pdf1.Types of Computer Information SystemsThere are four basic type.pdf
1.Types of Computer Information SystemsThere are four basic type.pdf
arccreation001
 
Microbiome of human bodyResearchers currently studying human norm.pdf
Microbiome of human bodyResearchers currently studying human norm.pdfMicrobiome of human bodyResearchers currently studying human norm.pdf
Microbiome of human bodyResearchers currently studying human norm.pdf
arccreation001
 
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdfNa2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
arccreation001
 
It is an important to understand the early stages of reproduction. W.pdf
It is an important to understand the early stages of reproduction. W.pdfIt is an important to understand the early stages of reproduction. W.pdf
It is an important to understand the early stages of reproduction. W.pdf
arccreation001
 
Let the normal gene be represented by P, and the two mutations be re.pdf
Let the normal gene be represented by P, and the two mutations be re.pdfLet the normal gene be represented by P, and the two mutations be re.pdf
Let the normal gene be represented by P, and the two mutations be re.pdf
arccreation001
 
Imagine you are an Information Systems Security Officer for a medium.pdf
Imagine you are an Information Systems Security Officer for a medium.pdfImagine you are an Information Systems Security Officer for a medium.pdf
Imagine you are an Information Systems Security Officer for a medium.pdf
arccreation001
 
Each water molecule has 4 hydrogen bonds holding .pdf
                     Each water molecule has 4 hydrogen bonds holding .pdf                     Each water molecule has 4 hydrogen bonds holding .pdf
Each water molecule has 4 hydrogen bonds holding .pdf
arccreation001
 
2) In Autocrine signalling, reception of a signal released by the sa.pdf
2) In Autocrine signalling, reception of a signal released by the sa.pdf2) In Autocrine signalling, reception of a signal released by the sa.pdf
2) In Autocrine signalling, reception of a signal released by the sa.pdf
arccreation001
 
Volatility Distillation separates out different .pdf
                     Volatility  Distillation separates out different .pdf                     Volatility  Distillation separates out different .pdf
Volatility Distillation separates out different .pdf
arccreation001
 
The first one has Van der Waals interactions sinc.pdf
                     The first one has Van der Waals interactions sinc.pdf                     The first one has Van der Waals interactions sinc.pdf
The first one has Van der Waals interactions sinc.pdf
arccreation001
 
Supersaturated actually. There is more solvent th.pdf
                     Supersaturated actually. There is more solvent th.pdf                     Supersaturated actually. There is more solvent th.pdf
Supersaturated actually. There is more solvent th.pdf
arccreation001
 
In optics, a virtual image is an image in which t.pdf
                     In optics, a virtual image is an image in which t.pdf                     In optics, a virtual image is an image in which t.pdf
In optics, a virtual image is an image in which t.pdf
arccreation001
 
1) Political orientation and ideas are the main reasons behind count.pdf
1) Political orientation and ideas are the main reasons behind count.pdf1) Political orientation and ideas are the main reasons behind count.pdf
1) Political orientation and ideas are the main reasons behind count.pdf
arccreation001
 
Molarity = moles volume in L Molarity = 0.0342.pdf
                     Molarity = moles  volume in L Molarity = 0.0342.pdf                     Molarity = moles  volume in L Molarity = 0.0342.pdf
Molarity = moles volume in L Molarity = 0.0342.pdf
arccreation001
 
The tracheal system in insects and gills in fishes are both helps th.pdf
The tracheal system in insects and gills in fishes are both helps th.pdfThe tracheal system in insects and gills in fishes are both helps th.pdf
The tracheal system in insects and gills in fishes are both helps th.pdf
arccreation001
 
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdfThe answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
arccreation001
 
The A and B chains of human insulin are cloned in separate plasmids .pdf
The A and B chains of human insulin are cloned in separate plasmids .pdfThe A and B chains of human insulin are cloned in separate plasmids .pdf
The A and B chains of human insulin are cloned in separate plasmids .pdf
arccreation001
 
Question 1How many parameters does a default constructor haveAn.pdf
Question 1How many parameters does a default constructor haveAn.pdfQuestion 1How many parameters does a default constructor haveAn.pdf
Question 1How many parameters does a default constructor haveAn.pdf
arccreation001
 
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdfRio de Janeiro is a city located on Brazils south-east coast. It i.pdf
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
arccreation001
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
arccreation001
 
1.Types of Computer Information SystemsThere are four basic type.pdf
1.Types of Computer Information SystemsThere are four basic type.pdf1.Types of Computer Information SystemsThere are four basic type.pdf
1.Types of Computer Information SystemsThere are four basic type.pdf
arccreation001
 
Microbiome of human bodyResearchers currently studying human norm.pdf
Microbiome of human bodyResearchers currently studying human norm.pdfMicrobiome of human bodyResearchers currently studying human norm.pdf
Microbiome of human bodyResearchers currently studying human norm.pdf
arccreation001
 
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdfNa2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
arccreation001
 
It is an important to understand the early stages of reproduction. W.pdf
It is an important to understand the early stages of reproduction. W.pdfIt is an important to understand the early stages of reproduction. W.pdf
It is an important to understand the early stages of reproduction. W.pdf
arccreation001
 
Let the normal gene be represented by P, and the two mutations be re.pdf
Let the normal gene be represented by P, and the two mutations be re.pdfLet the normal gene be represented by P, and the two mutations be re.pdf
Let the normal gene be represented by P, and the two mutations be re.pdf
arccreation001
 
Imagine you are an Information Systems Security Officer for a medium.pdf
Imagine you are an Information Systems Security Officer for a medium.pdfImagine you are an Information Systems Security Officer for a medium.pdf
Imagine you are an Information Systems Security Officer for a medium.pdf
arccreation001
 
Each water molecule has 4 hydrogen bonds holding .pdf
                     Each water molecule has 4 hydrogen bonds holding .pdf                     Each water molecule has 4 hydrogen bonds holding .pdf
Each water molecule has 4 hydrogen bonds holding .pdf
arccreation001
 
Ad

Recently uploaded (20)

TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Ad

SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf

  • 1. SOURCE CODE: import java.util.Iterator; public class CircularLinkedList implements Iterable { Node head , tail; int size; CircularLinkedList() { head = null; tail = null; size = 0; } public boolean add(E e) { Node ele = new Node(e); ele.next = head; if(head == null) { head = ele; ele.next = head; tail = head; } else { tail.next = ele; tail = ele; } size++; return true; } public boolean add(int index, E e){ Node ele = new Node(e); Node ptr = head; index = index - 1 ;
  • 2. for (int i = 1; i < size - 1; i++) { if (i == index) { Node tmp = ptr.next; ptr.next = ele; ele.next = tmp; break; } ptr = ptr.next; } size++ ; return true; } private Node getNode(int index ) { return null; } public E remove(int index) { Node ret; if (size == 1 && index == 1) { ret = head; head = null; tail = null; size = 0; return ret.getElement(); } if (index == 1) { ret = head; head = head.next; tail.next = head; size--; return ret.getElement(); }
  • 3. if (index == size) { Node s = head; Node t = head; while (s != tail) { t = s; s = s.next; } ret = tail; tail = head; tail = t; size --; return ret.getElement(); } Node ptr = head; index = index - 1 ; for (int i = 1; i < size - 1; i++) { if (i == index) { Node tmp = ptr.next; tmp = tmp.next; ptr.next = tmp; break; } ptr = ptr.next; } size-- ; return ptr.getElement(); } public String toString() { Node current = head; String result = ""; if(size == 0){
  • 4. return ""; } if(size == 1) { return head.getElement().toString(); } else{ do{ result = result + current.getElement().toString(); result = result + " ==> "; current = current.next; } while(current != head); } return result; } public Iterator iterator() { return new ListIterator(); } private class ListIterator implements Iterator{ Node nextItem; Node prev; int index; @SuppressWarnings("unchecked") public ListIterator(){ nextItem = (Node) head; index = 0; } public boolean hasNext() { return size != 0; }
  • 5. public E next() { prev = nextItem; nextItem = nextItem.next; index = (index + 1) % size; return prev.getElement(); } public void remove() { int target; if(nextItem == head) { target = size - 1; } else{ target = index - 1; index--; } CircularLinkedList.this.remove(target); //calls the above class } } // Solve the problem in the main method // The answer of n = 13, k = 2 is // the 11th person in the ring (index 10) public static void main(String[] args){ CircularLinkedList l = new CircularLinkedList(); int n=13; int k=2; for(int i=1;i<=n;i++) l.add(Integer.valueOf(i)); int j = 13,i=0; while(j>0) { System.out.println(l.toString());
  • 6. i = i + k; if(i>j) i = k; l.remove(i); j--; } } } OUTPUT: 1 ==> 2 ==> 3 ==> 4 ==> 5 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==> 1 ==> 3 ==> 4 ==> 5 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==> 1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==> 1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==> 1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 12 ==> 13 ==> 1 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 12 ==> 13 ==> 1 ==> 4 ==> 6 ==> 9 ==> 10 ==> 12 ==> 13 ==> 1 ==> 4 ==> 6 ==> 9 ==> 10 ==> 13 ==> 1 ==> 6 ==> 9 ==> 10 ==> 13 ==> 1 ==> 6 ==> 9 ==> 13 ==> 1 ==> 9 ==> 13 ==> 1 ==> 13 ==> 1 Solution SOURCE CODE: import java.util.Iterator; public class CircularLinkedList implements Iterable { Node head , tail; int size; CircularLinkedList() { head = null; tail = null;
  • 7. size = 0; } public boolean add(E e) { Node ele = new Node(e); ele.next = head; if(head == null) { head = ele; ele.next = head; tail = head; } else { tail.next = ele; tail = ele; } size++; return true; } public boolean add(int index, E e){ Node ele = new Node(e); Node ptr = head; index = index - 1 ; for (int i = 1; i < size - 1; i++) { if (i == index) { Node tmp = ptr.next; ptr.next = ele; ele.next = tmp; break; } ptr = ptr.next; }
  • 8. size++ ; return true; } private Node getNode(int index ) { return null; } public E remove(int index) { Node ret; if (size == 1 && index == 1) { ret = head; head = null; tail = null; size = 0; return ret.getElement(); } if (index == 1) { ret = head; head = head.next; tail.next = head; size--; return ret.getElement(); } if (index == size) { Node s = head; Node t = head; while (s != tail) { t = s; s = s.next; } ret = tail; tail = head;
  • 9. tail = t; size --; return ret.getElement(); } Node ptr = head; index = index - 1 ; for (int i = 1; i < size - 1; i++) { if (i == index) { Node tmp = ptr.next; tmp = tmp.next; ptr.next = tmp; break; } ptr = ptr.next; } size-- ; return ptr.getElement(); } public String toString() { Node current = head; String result = ""; if(size == 0){ return ""; } if(size == 1) { return head.getElement().toString(); } else{ do{ result = result + current.getElement().toString(); result = result + " ==> "; current = current.next;
  • 10. } while(current != head); } return result; } public Iterator iterator() { return new ListIterator(); } private class ListIterator implements Iterator{ Node nextItem; Node prev; int index; @SuppressWarnings("unchecked") public ListIterator(){ nextItem = (Node) head; index = 0; } public boolean hasNext() { return size != 0; } public E next() { prev = nextItem; nextItem = nextItem.next; index = (index + 1) % size; return prev.getElement(); } public void remove() { int target;
  • 11. if(nextItem == head) { target = size - 1; } else{ target = index - 1; index--; } CircularLinkedList.this.remove(target); //calls the above class } } // Solve the problem in the main method // The answer of n = 13, k = 2 is // the 11th person in the ring (index 10) public static void main(String[] args){ CircularLinkedList l = new CircularLinkedList(); int n=13; int k=2; for(int i=1;i<=n;i++) l.add(Integer.valueOf(i)); int j = 13,i=0; while(j>0) { System.out.println(l.toString()); i = i + k; if(i>j) i = k; l.remove(i); j--; } } } OUTPUT: 1 ==> 2 ==> 3 ==> 4 ==> 5 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==>
  • 12. 1 ==> 3 ==> 4 ==> 5 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==> 1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 8 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==> 1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 11 ==> 12 ==> 13 ==> 1 ==> 3 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 12 ==> 13 ==> 1 ==> 4 ==> 6 ==> 7 ==> 9 ==> 10 ==> 12 ==> 13 ==> 1 ==> 4 ==> 6 ==> 9 ==> 10 ==> 12 ==> 13 ==> 1 ==> 4 ==> 6 ==> 9 ==> 10 ==> 13 ==> 1 ==> 6 ==> 9 ==> 10 ==> 13 ==> 1 ==> 6 ==> 9 ==> 13 ==> 1 ==> 9 ==> 13 ==> 1 ==> 13 ==> 1
  翻译: