The Codeground

class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def append(self, data): new_node = Node(data) if not self.head: self.head = new_node return last_node = self.head while last_node.next: last_node = last_node.next last_node.next = new_node def print_list(self): current_node = self.head while current_node: print(current_node.data, end=" -> ") current_node = current_node.next print("None") def reverse_linked_list(head): prev = None current = head while current: next_node = current.next current.next = prev prev = current current = next_node return prev def is_circular_linked_list(head): slow = fast = head while fast and fast.next: slow = slow.next fast = fast.next.next if slow == fast: return True return False def merge_sorted_linked_lists(l1, l2): dummy = Node(0) tail = dummy while l1 and l2: if l1.data < l2.data: tail.next = l1 l1 = l1.next else: tail.next = l2 l2 = l2.next tail = tail.next tail.next = l1 or l2 return dummy.next def find_middle_of_linked_list(head): slow = fast = head while fast and fast.next: slow = slow.next fast = fast.next.next return slow def remove_nth_from_end(head, n): dummy = Node(0) dummy.next = head fast = slow = dummy for _ in range(n + 1): fast = fast.next while fast: fast = fast.next slow = slow.next slow.next = slow.next.next return dummy.next def is_palindrome_linked_list(head): slow = fast = head while fast and fast.next: slow = slow.next fast = fast.next.next prev = None while slow: next_node = slow.next slow.next = prev prev = slow slow = next_node first_half = head second_half = prev while second_half: if first_half.data != second_half.data: return False first_half = first_half.next second_half = second_half.next return True def remove_duplicates_sorted(head): current = head while current and current.next: if current.data == current.next.data: current.next = current.next.next else: current = current.next return head def rotate_right(head, k): if not head or k == 0: return head length = 1 tail = head while tail.next: tail = tail.next length += 1 tail.next = head k = k % length steps_to_new_head = length - k new_tail = head for _ in range(steps_to_new_head - 1): new_tail = new_tail.next new_head = new_tail.next new_tail.next = None return new_head # Example usage: llist = LinkedList() llist.append(1) llist.append(2) llist.append(3) llist.append(4) llist.append(5) # Reverse Linked List llist.head = reverse_linked_list(llist.head) llist.print_list() # Check if Circular Linked List print(is_circular_linked_list(llist.head)) # Merge Two Sorted Linked Lists llist1 = LinkedList() llist1.append(1) llist1.append(3) llist1.append(5) llist2 = LinkedList() llist2.append(2) llist2.append(4) llist2.append(6) merged_head = merge_sorted_linked_lists(llist1.head, llist2.head) llist = LinkedList() llist.head = merged_head llist.print_list() # Find the Middle of a Linked List middle_node = find_middle_of_linked_list(llist.head) print("Middle node data:", middle_node.data) # Remove N-th Node from End llist.head = remove_nth_from_end(llist.head, 2) llist.print_list() # Check if Palindrome Linked List llist_palindrome = LinkedList() llist_palindrome.append(1) llist_palindrome.append(2) llist_palindrome.append(3) llist_palindrome.append(2) llist_palindrome.append(1) print(is_palindrome_linked_list(llist_palindrome.head)) # Remove Duplicates from Sorted Linked List llist_dup = LinkedList() llist_dup.append(1) llist_dup.append(1) llist_dup.append(2) llist_dup.append(3) llist_dup.append(3) llist_dup.head = remove_duplicates_sorted(llist_dup.head) llist_dup.print_list() # Rotate Linked List to the Right llist_rot = LinkedList() llist_rot.append(1) llist_rot.append(2) llist_rot.append(3) llist_rot.append(4) llist_rot.append(5) llist_rot.head = rotate_right(llist_rot.head, 2) llist_rot.print_list()
Hint: Remember to include output statements in your code, such as print, console.log, printf, fmt.Println() or System.out.println.

Benefits of TheCodeground Online IDE

Multi-Language Support

TheCodeground Online IDE supports C++, Java, Node.js, Python, and more, making it an incredibly versatile tool for diverse coding needs. This extensive language support allows developers to work on different projects within a single platform.

Real-Time Collaboration

Our real-time collaboration feature enables multiple developers to work on the same project simultaneously, enhancing teamwork and productivity. This feature is particularly beneficial for remote teams and pair programming sessions.

User-Friendly Interface

Designed with a clean and intuitive interface, TheCodeground Online IDE simplifies coding and debugging processes, making it accessible for users of all skill levels. The ease of use and clear navigation ensure a smooth coding experience.

Instant Code Execution

Experience fast and efficient code execution with immediate feedback in the integrated terminal. This feature helps streamline the development process, allowing developers to quickly test and debug their code.

Free to Use

Enjoy the full range of features at no cost. TheCodeground Online IDE is completely free, providing a valuable resource for developers without any subscription fees. This makes it an ideal choice for students, hobbyists, and professionals alike.

Cloud-Based Platform

As a cloud-based IDE, TheCodeground allows you to access your projects from anywhere, at any time. This flexibility ensures that you can continue coding without being tied to a specific device or location.

Customizable Environment

Tailor the IDE to your preferences with customizable themes, layouts, and extensions. This personalization ensures a comfortable and productive coding environment.

Why Choose TheCodeground Over Other Online IDEs?

TheCodeground Online IDE stands out from the competition with its comprehensive feature set, ease of use, and cost-effectiveness. Unlike many other online IDEs that require subscriptions or offer limited free plans, TheCodeground provides all its features for free. Our multi-language support, real-time collaboration, and advanced debugging tools ensure that you have everything you need for effective development. Additionally, our user-friendly interface and customizable environment make coding a pleasant experience, regardless of your expertise level. Choose TheCodeground Online IDE for a seamless, efficient, and enjoyable coding experience.

×
Ground visible to everyone?
No
Yes
Ground editable by everyone?
No
Yes
Get a new ground?