Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I've provided a Node class that implements a node of a simple singly-linked list (with .value and .next fields), and an empty LinkedList class. Your

I've provided a Node class that implements a node of a simple singly-linked list (with .value and .next fields), and an empty LinkedList class. Your task is to implement LinkedList.sort(l), where given the node l as the head of a singly-linked list, LinkedList.sort(l) sorts the nodes in the list into ascending order according to the values in the .value field of each node.

Your implementation should do an in-place update of the list. It is ok to use a simple O(n**2) algorithm.

Examples

1. 'b'->'a'->'d'->'c' sorts to 'a'->'b'->'c'->'d'

2. 3->2->1 sorts to 1->2->3

3. "this"->"that" sorts to "that"->"this"

node.py

class Node: """Simple node for singly-linked list""" def __init__(self, value, next=None): """Create a new node, with optional next node pointer""" self.value = value self.next = next

linkedlist.py

from node import Node class LinkedList: @staticmethod def sort(l): """Simple in-place sort of singly-linked list whose head is l""" # TODO Replace "pass" with your sort pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago