Giter Club home page Giter Club logo

Comments (3)

deepak-malik avatar deepak-malik commented on June 11, 2024

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.

simohamedhdafa avatar simohamedhdafa commented on June 11, 2024

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.

simohamedhdafa avatar simohamedhdafa commented on June 11, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.