#๐Ÿ”’ Circular Doubly Linked List

44 messages ยท Page 1 of 1 (latest)

lunar grotto
#

Hello, I am creating a doubly linked list class but I am unsure how to make it so I get the current node. The concept behind this is that I am making a carousel of images and if I add an image/node then that node becomes the current node and I either add to the left or right of that node. If I decide to remove from that node then it'll remove the left/previous of the current node and then the current becomes the previous. I'll figure out how the add and remove methods but I'm just unsure of how I can start the get current node method.

lethal canyonBOT
#

@lunar grotto

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lunar grotto
#

Here is my node class.

fluid glacier
#

!code

lethal canyonBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

fluid glacier
lunar grotto
fluid glacier
#

though it looks like your assignment wants you to pretend that there is

#

oh well.

#

@lunar grotto can you show the definition for the doubly linked list class? you've only shown the node class. please post it as text--not as a screenshot.

lunar grotto
#

!code

lethal canyonBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

lunar grotto
#

How do you send it as code

#

?

fluid glacier
#

you have to follow the instructions in the message. you do not need to say "!code" again

fluid glacier
lethal canyonBOT
#

Hey @lunar grotto!

It looks like you are trying to paste code into this channel.

You seem to be using the wrong symbols to indicate where the code block should start. The correct symbols would be ```, not '''.

Furthermore, it looks like you pasted Python code without syntax highlighting. Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
lunar grotto
#
class CircularDoublyLinkedList:
    def __init__(self, capacity):
        self.head = None
        self.tail = None
        self.size = 0
        self.capacity = capacity
        self.current = None

    def isFull(self):
        return self.size >= self.capacity
    
    def isEmpty(self):
        return self.size == 0
    
    def add(self, item):
        if self.isFull():
            raise Exception("Carousel is Full.")
        
        new_node = DLinkedListNode(item, self.head, None)
        if self.head is None:
            self.head = new_node
            self.tail = new_node
            self.current = new_node
        self.size = 1
#

Okay got it

fluid glacier
#

you forgot the py, but that's fine. please do not delete it again.

lunar grotto
#

So far this is what I have

fluid glacier
#

do the instructions contain any other references to the "current node"?

lunar grotto
#

No should only be head and tail

#

If it's in the middle then we just swap

fluid glacier
#

but the instructions say you need a method for getting the "active/current node"

lunar grotto
#

by doing current.setPrevious and current.setNext

fluid glacier
#

how does a node become the current node?

lunar grotto
#

Yes and I can do that by adding another method that just does self.current.getData()

#

the node becomes the current node if I make self.current = new_node

#

because when I add I have to create a new_node

fluid glacier
#

okay. do you want to focus on just getting the add method to work?

lunar grotto
#

What I am planning on doing was just to make 2 other methods, addLeft and addRight, then once those are done I can do the remove method, which is only removing the current node, I don't have to specify what position or item.

#

The current will change when I call the methods for the object outside of the class

#

in the class I am only trying to set its position and where it points to

#

That was my general idea on the problem

fluid glacier
#

Okay. What issues are you facing currently?

lunar grotto
#

When I sent the code I didn't know how to start so I was just wondering if my approach to the problem was something that would work or if I need to change anything so that I won't have issues later.

fluid glacier
lunar grotto
#

Later on I have to have to prompt the user to either add left or right so I thought it would be easier to implement that when I have 2 methods for each case and just add for when the list is empty

lethal canyonBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.