Let's get right to the chase, I have a college-level data structures (on Java) exam on recursion, stacks...

Let's get right to the chase, I have a college-level data structures (on Java) exam on recursion, stacks, queues and iterators next week
I'm having problems with implementations using linked lists, any tips on how to learn these topics by myself in less than a week? I have the basic knowledge on how to work with linked lists and array lists, and I have no problem with recursion or iterators

download more knowledge

Where do you recommend doing so? I already downloaded my fill of RAM

When I was learning this stuff, what I did is draw pictures. I drew pictures of each process to help me understand it.

Here's an example of a drawing I made for a linked list add in the middle of two nodes:

thanks man, I'll try that
Here's a small question, if I can access previous nodes on a linked list, I can just go to the previous node from a target node and delete it if need be? Asking because my professor says I had to do a while loop from the head until the the node before target, then do nodeToDelete.clear(), then set the list size and he fucked my grade up

Well you can't go backwards on a single linked list, only a double linked list.

If you wanna clear a list, you would just set the firstNode variable, and any other variables that might be pointed to any nodes in the list, to null and then garbage collection would clear it all up.

Sorry, forgot to mention it was a doubly linked list, since I just used the following loop for a singly linked list:
while(nodeToDelete.getNext()!=targetNode){
nodeToDelete.getNext();
}
nodeTodelete.clear();
size--;

Should this be sensible enough? Or is there something else wrong? There's no way to test the code since the test is handwritten (also sorry if the code doesn't appear correctly, I've never posted code snippets here)

Why the fuck would they teach this shit with java? Nobody is ever going to do any of that in java. Recursion in java is terrible, stacks are ok but nobody would implement their own stack in java, and pretty much any data structure you'd use in java can be iterated without implementing a iterator yourself and without calling creating a iterator implicitly.

Why do they teach such useless stuff in college?

Because muh "advanced programming" course is also taught in java and the only professor who is willing to give that class has such a fucking hard on for it

That code looks like it deletes the node before the target node. Also that doesn't seem right. You're supposed to target the data, not the node itself. Someone using your list shouldn't need to know about the nodes.

Is the method supposed to remove an entry based on the position or based on the data?

It's supposed to delete the node before the target node, and it's supposed to remove based on the position, it searches an object targetNode of type Node on the list and does what I posted on the snippet.

So the clear method reassigns all the pointers for you? Did you write it or was it given?

It's assumed that the Node subclass contains any and all methods for assigning, clearing and setting nodes to their respective places
>tfw the professor marked my code as wrong but he wrote "excellent!" under the time complexity analysis

Wow, you have it easy. Normally you're supposed to write your own code to manually reassign the next and prev nodes.

Yes, you can just delete any node in the list you want.
However, if you're deleting the first or last node there might be some issue when setting the first and prev node member variables. Depending on the implementation, you would set the firstNode to the firstNode.next before clearing the first node, and the same but reversed for removing the last node.

Thanks, I'm really not giving much details but the exams themselves have some good ideas on how to implement the code
In the case of this exercise, the list has both a dummy head and tail (if a doubly linked list), it's assumed that no exceptions will be triggered by the testers so basically all you have to do is write a properly indented code snippet of the method
I assume this test will include parts to make a push, pop, queue and dequeue methods, which luckily I have implemented with little issues
There's also this shit about a positional list, for which the professor has recommended we implement using both types of linked lists, and also using arrayLists

>college

Just cheat dude. Buy a UV pen and write all the algorithms or functions that you know you'll need on a white sheet of paper. Bring it to class and say that it's for scratch paper.

I did this for 4 years and it never raised an eyebrow. The only time was when a professor asked why I would need scratch paper, I just told him that I need to visually draw out the algorithm, but that only happened once.

>he doesn't understand linked lists
just drop out 2bh

they're probably the easiest data structure of all time

That likely won't happen since the professor is actually autistic and doesn't allow anything other than a #2 wooden pencil (no mechanical pencils allowed) and an eraser with nothing wrapped on it so no way to cheat on that
Also he doesn't make eye contact with anyone at all, which makes going to his office a hilarious and shitty experience at the same time
I do understand them but their implementation always fucks me up during exams

that doesn't make any sense. if you understood them, then the implementation should be a piece of cake.

just remember the technique to get to the end and you're pretty much fine

node *current = head;
while(current != nullptr)
current = current->next;
return current;


and for finding a specific index:
node* getIndex(short index)
{
short currentIndex = 0;
node *current = head;

while(currentIndex != index)
{
current = current->next;
++currentIndex
}

return current;
}

that pretty much covers linked lists. if you understand them conceptually and have those tools under your belt, you're good to go

I'm not good with exams, like the handwitten stuff
I aced the advanced programming class because it was an online JUnit test thing where you could code and test along the way and it made things a whole lot less stressing
I failed 3 classes in my college career due to stress alone