[Solved] Link lists in C++ (pt. 2) [closed]

You didn’t show us the code for del_begin(), but your del_end() has a bug in the case you’re mentioning (single node list). If you have only one node, your while loop will never execute, and temp2 will be uninitialized when you get to the line: temp2->nxt = NULL; Crash! 6 solved Link lists in C++ … Read more

[Solved] How does a linked list with Node class work in C++?

A nice tutorial is at: http://www.zentut.com/c-tutorial/c-linked-list/ From a programming perspective, normally your LinkedList class would have some methods to do the things you asked about, for example: Add – create a new entry at the end of the linked list InsertAfter(Node *n) – create a new entry after indicated node in the listed list Remove(Node … Read more

[Solved] Time limit exceeded – Fibonacci

Optimization comes usually comes in steps. You start off with the obvious solution. iterate_fibs_mod10; remove_odds(n); Then you realize that you really only need the expensive modulus once for one element. nth_fib(remove_odds(n))%10; Then you realize you don’t need to remove the nodes if you can deterministically find which one would have remained. nth_fib(as_if_remove_odds(n))%10; Then you figure … Read more

[Solved] Why am I stuck in displaying my linked list?

You weren’t assigning newnode to newnode->next, therefore no linked list was being created. But your code in the linked list doesn’t break or anything, it prints the values you wanted, just not in a linked list. The problem may be with conio.h, which is of no use in this code. remove #include <conio.h> and getch_(); … Read more

[Solved] Why isn’t length(self.next) a valid expression in python? [closed]

What is length? length does not exist, but Node.length does. The reason return(1+length(self.next)) doesn’t work is because you’re calling length(), not Node.length(). Instead, try this: return(1+LinkedList.length(self.next)) Or this (my preference): return(1+self.next.length()) solved Why isn’t length(self.next) a valid expression in python? [closed]

[Solved] C programming error in code [closed]

If any more questions don’t doubt to contact me. Good luck. About createlist() Head should point to the first element of the list, but you are using head to instantiate the newest element added to the list. First and head conceptually are the same. I think you think head should be the last element of … Read more

[Solved] Null Pointer Exception, Cant figure out why? [closed]

I did not understand how the output you showed has one of the numbers multiplied by 100 in each element of String array. Based on my understanding of your question here is a solution. import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Shifts { public static void main(String[] args) { LinkedList<Integer> … Read more

[Solved] How to copy linked list in Python?

this should be working: import copy class _ListNode: def __init__(self, value, next_): self._value = copy.deepcopy(value) self._next = next_ return class List: def __init__(self): self._front = None self._count = 0 return def addToFront(self, value): if self._front == None: self._front = _ListNode(value, None) else: buffer = _ListNode(value, self._front) self._front = buffer def addToEnd(self, value): current = self._front … Read more

[Solved] combine items of list

public class Main { public static void main(String[] args) { List<Integer> list = new LinkedList<>(); list.add(30); list.add(50); list.add(5); list.add(60); list.add(90); list.add(5); list.add(80); System.out.println(list); combine(list, 2, 3); System.out.println(list); } public static void combine(List<Integer> list, int indexA, int indexB) { Integer a = list.get(indexA); Integer b = list.get(indexB); list.remove(indexB); // [30, 50, 5, 90, 5, 80] list.add(indexA, … Read more