#!/bin/python3
import math
import os
import random
import re
import sys
class DoublyLinkedListNode:
def __init__(self, node_data):
self.data = node_data
self.next = None
self.prev = None
class DoublyLinkedList:
def __init__(self):
self.head = None
self.tail = None
def insert_node(self, node_data):
node = DoublyLinkedListNode(node_data)
if not self.head:
self.head = node
else:
self.tail.next = node
node.prev = self.tail
self.tail = node
def print_doubly_linked_list(node, sep, fptr):
while node:
fptr.write(str(node.data))
node = node.next
if node:
fptr.write(sep)
# Complete the sortedInsert function below.
#
# For your reference:
#
# DoublyLinkedListNode:
# int data
# DoublyLinkedListNode next
# DoublyLinkedListNode prev
#
#
def sortedInsert(head, data):
new=DoublyLinkedListNode(data)
if new.data<=head.data:
new.next=head
return new
tmp=head
while tmp.next:
if new.data<=tmp.next.data:
print(tmp.data)
tmp1=tmp.next
new.next=tmp1
tmp.next=new
return head
tmp=tmp.next
tmp.next=new
print('w')
return head
if __name__ == '__main__':