Issue turning a node linkedlist to generic type node linkedlist (this is what I tried)

public class LinkedListf<E> { static class node <E>{ E data; node<E> next; node(E value) { data = value; next = null; } } static node head; // display the list static void printList() { node p = head; System.out.print("\n["); //start from the beginning while(p != null) { System.out.print(" " + p.data + " "); p = p.next; } System.out.print("]"); } //insertion at the beginning void insertatbegin(E data) { //create a link node lk = new node(data); // point it to old first node lk.next = head; //point first to new first node head = lk; //pointing old node to new node } void deletedata(E data){ node del = head; node prev = null; if(del != null && del.data == data){ head= del.next; return; } while (del != null && del.data != data){ prev = del; del= del.next; } prev.next=del.next; } void insertafter(E index, E data){ node sert = head; //node prev = null; node ins = new node(data); while (sert != null){ if(sert.data == index){ ins.next = sert.next; sert.next = ins; break; } sert = sert.next; } } public static void main(String args[]) { int k=0; insertatbegin(12); insertatbegin(22); insertatbegin(30); deletedata(12); insertafter(44, 2); System.out.println("Linked List: "); // print list printList(); } } //issue is im not sure if its correct, and I get a cannot run from a static point because I had to change the functions from static when trying to call the functions in MAIN as is.
100 Replies
JavaBot
JavaBotā€¢2y ago
āŒ› This post has been reserved for your question.
Hey @Alpha! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBotā€¢2y ago
Please format your code & make it more readable. For the java programming language, it should look like this:
```java public class Main{ public static void main(String[] args){ System.out.println("Hello World!"); } }```
ā€¢ These are backticks, not quotes.
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
is it not the title? or did I miss a part?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I put at the bottom of the code
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I got it to work Am I allowed to post the code for you to see? here @That_Guy977
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
yes
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I haven't learned PascalCase
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
i usual call it camelBack notation, was confused but i get it
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
so it's Node not node?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
at the class or all of them?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
yes i did it also It needs to be able to input integers and strings is it good as is or do I need to create a object for the list?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
oh sht I forgot i put that in bare with me im kind of special so its good ?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I'm doomed
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
oki doke LinkedListf<String> StringList = new LinkedListf<>(); would that be generic instead of : LinkedListf listf = new LinkedListf(); ?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
ah ha i GET IT NOW but would i get added to another list?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
so since it doesn't do this anymore
No description
Alpha
AlphaOPā€¢2y ago
would one object list have all strings and another have all intergers?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
No description
Alpha
AlphaOPā€¢2y ago
Im guessing that means two different lists
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
is this what it should do?
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I didn't even call String list
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
this is both intList and stringList
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I still had a static head
No description
Alpha
AlphaOPā€¢2y ago
sorry lol but its that correct?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
You're alot smarter than me idk how to fix it
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I was about to slap this bitch in for submission did I?:pepesusthink:
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
i can't even refractor lol give me some time
Alpha
AlphaOPā€¢2y ago
This is the best I could do
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
yes It looks so good there i don't wanna change it šŸ˜¦
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I don't know what indices are
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
maybe
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
whaaa
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
it won't allow me to put index function variable as int
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
i have function(E index)
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
i know i just randomly named it that
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
i was suppose to name it replace
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
i don't know what I mean ok
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
this is it
No description
Alpha
AlphaOPā€¢2y ago
what would I name it?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
ok i'll change it
Alpha
AlphaOPā€¢2y ago
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
yes i refractored all of indices to after
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
i deleted that i don't get how previous works
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
for the delete method my teacher wrote that i don't understand it the delete function has a prev to go back through the list but I don't understand it
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
how i do dat?
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I debugged the prev variable
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
Alpha
AlphaOPā€¢2y ago
I've never really studied that
Alpha
AlphaOPā€¢2y ago
this?
No description
Unknown User
Unknown Userā€¢2y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBotā€¢2y ago
šŸ’¤ Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.

Did you find this page helpful?