Comments (3)
Thanks for finding this issue. Can you please explain a bit more what is happening when you try to delete items? Is there any exception? Also if you can raise a pull request for the issue, that will be great.
from data-structures-in-java.
My pleasure. As I wanted to show with the code above, when I try to delete all the items, except a last one from the CircularLinkedList g that I created, the g.size() returns an incorrect answer. To be sure, I display the list and there are already items there ! You can execute the main method to get a better understanding of the issue. If there is a chance I may not have fully understood the use of your CircularLinkedList class, please let me know where I missed it.
from data-structures-in-java.
I found the issue. In the method deleteFromPosition( ) the size decrementation should be written in the else bloc, like this :
public void deleteFromPosition(int position) {
if (position < 0 || position >= size) {
throw new IllegalArgumentException("Position is Invalid");
}
Node<E> current = head, previous = head;
for (int i = 0; i < position; i++) {
if (current.next == head) {
break;
}
previous = current;
current = current.next;
}
if (position == 0) {
deleteFromBeginning();
} else {
previous.next = current.next;
size--;
}
}
from data-structures-in-java.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data-structures-in-java.