




'''simple docstring'''







import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


A									=False
try:
   A									=_is_package_available('google.colab')
except ModuleNotFoundError:
   pass


@input.register
class     _a						:
       def __init__(			self		:			int     ,       lowercase		:			str = None     ,       lowercase		:			list = []       ):



           '''simple docstring'''

           UpperCAmelCase     =	0
           UpperCAmelCase     =	choices
           UpperCAmelCase     =	prompt
           if sys.platform == "win32":
               UpperCAmelCase     =	'''*'''
           else:
               UpperCAmelCase     =	'''➔ '''
       def 					A   (			self		:			Any     ,       lowercase		:			Tuple     ,       lowercase		:			str = ""       ):



           '''simple docstring'''

           if sys.platform != "win32":
               writeColor(self.choices[index]     ,       32     ,       lowercase       )
           else:
               forceWrite(self.choices[index]     ,       lowercase       )
       def 					A   (			self		:			Optional[Any]     ,       lowercase		:			int       ):



           '''simple docstring'''

           if index == self.position:
               forceWrite(f" {self.arrow_char} "       )
               self.write_choice(lowercase       )
           else:
               forceWrite(f"    {self.choices[index]}"       )
           reset_cursor()
       def 					A   (			self		:			List[str]     ,       lowercase		:			Direction     ,       lowercase		:			int = 1       ):



           '''simple docstring'''

           UpperCAmelCase     =	self.position
           if direction == Direction.DOWN:
               if self.position + 1 >= len(self.choices       ):
                   return
               self.position += num_spaces
           else:
               if self.position - 1 < 0:
                   return
               self.position -= num_spaces
           clear_line()
           self.print_choice(lowercase       )
           move_cursor(lowercase     ,       direction.name       )
           self.print_choice(self.position       )
       @input.mark(KEYMAP['''up''']       )
       def 					A   (			self		:			List[str]       ):



           '''simple docstring'''

           self.move_direction(Direction.UP       )
       @input.mark(KEYMAP['''down''']       )
       def 					A   (			self		:			Tuple       ):



           '''simple docstring'''

           self.move_direction(Direction.DOWN       )
       @input.mark(KEYMAP['''newline''']       )
       def 					A   (			self		:			List[Any]       ):



           '''simple docstring'''

           move_cursor(len(self.choices       ) - self.position     ,       '''DOWN'''       )
           return self.position
       @input.mark(KEYMAP['''interrupt''']       )
       def 					A   (			self		:			str       ):



           '''simple docstring'''

           move_cursor(len(self.choices       ) - self.position     ,       '''DOWN'''       )
           raise KeyboardInterrupt
       @input.mark_multiple(*[KEYMAP[str(lowercase       )] for number in range(10       )]       )
       def 					A   (			self		:			Optional[Any]       ):



           '''simple docstring'''

           UpperCAmelCase     =	int(chr(self.current_selection       )       )
           UpperCAmelCase     =	index - self.position
           if index == self.position:
               return
           if index < len(self.choices       ):
               if self.position > index:
                   self.move_direction(Direction.UP     ,       -movement       )
               elif self.position < index:
                   self.move_direction(Direction.DOWN     ,       lowercase       )
               else:
                   return
           else:
               return







       def 					A   (			self		:			Optional[Any]     ,       lowercase		:			int = 0       ):



           '''simple docstring'''

           if self.prompt:
               linebreak()
               forceWrite(self.prompt     ,       '''\n'''       )
               if in_colab:
                   forceWrite('''Please input a choice index (starting from 0), and press enter'''     ,       '''\n'''       )
               else:
                   forceWrite('''Please select a choice using the arrow or number keys, and selecting with enter'''     ,       '''\n'''       )
           UpperCAmelCase     =	default_choice
           for i in range(len(self.choices       )       ):
               self.print_choice(lowercase       )
               forceWrite('''\n'''       )
           move_cursor(len(self.choices       ) - self.position     ,       '''UP'''       )
           with cursor.hide():
               while True:
                   if in_colab:
                       try:
                           UpperCAmelCase     =	int(builtins.input()       )
                       except ValueError:
                           UpperCAmelCase     =	default_choice
                   else:
                       UpperCAmelCase     =	self.handle_input()
                   if choice is not None:
                       reset_cursor()
                       for _ in range(len(self.choices       ) + 1       ):
                           move_cursor(1     ,       '''UP'''       )
                           clear_line()
                       self.write_choice(lowercase     ,       '''\n'''       )
                       return choice










'''simple docstring'''







from typing import Any


class     _a						:
       def __init__(			self		:			int     ,       lowercase		:			Any       ):



           '''simple docstring'''

           UpperCAmelCase     =	data
           UpperCAmelCase     =	None






class     _a						:
       def __init__(			self		:			int       ):



           '''simple docstring'''

           UpperCAmelCase     =	None
       def 					A   (			self		:			int       ):



           '''simple docstring'''

           UpperCAmelCase     =	self.head
           while temp is not None:
               print(temp.data     ,       end=''' '''       )
               UpperCAmelCase     =	temp.next
           print()
       def 					A   (			self		:			List[str]     ,       lowercase		:			Any       ):



           '''simple docstring'''

           UpperCAmelCase     =	Node(lowercase       )
           UpperCAmelCase     =	self.head
           UpperCAmelCase     =	new_node







       def 					A   (			self		:			List[Any]     ,       lowercase		:			List[Any]     ,       lowercase		:			str       ):



           '''simple docstring'''

           if node_data_a == node_data_a:
               return
           else:
               UpperCAmelCase     =	self.head
               while node_a is not None and node_a.data != node_data_a:
                   UpperCAmelCase     =	node_a.next

               UpperCAmelCase     =	self.head
               while node_a is not None and node_a.data != node_data_a:
                   UpperCAmelCase     =	node_a.next

               if node_a is None or node_a is None:
                   return

               UpperCAmelCase ,  UpperCAmelCase     =	node_a.data, node_a.data


if __name__ == "__main__":
   A									=LinkedList()
   for i in range(5, 0, -1):
      ll.push(i)

   ll.print_list()

   ll.swap_nodes(1, 4)
   print('After swapping')
   ll.print_list()




