Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
def __init__(self, data):
self.data = data
self.next = None
class CircularLinkedList:
def __init__(self):
self.head = None
def append(self, data):
new_node = Node(data)
if not self.head:
self.head = new_node
new_node.next = self.head
else:
current = self.head
while current.next != self.head:
current = current.next
current.next = new_node
new_node.next = self.head
def display(self):
if not self.head:
print("List kosong")
return
current = self.head
while True:
print(current.data, end=" -> ")
current = current.next
if current == self.head:
break
print()
def delete(self, key):
if not self.head:
print("List kosong")
return
if self.head.data == key:
current = self.head
while current.next != self.head:
current = current.next
if self.head == self.head.next:
self.head = None
else:
self.head = self.head.next
current.next = self.head
return
current = self.head
prev = None
while current.next != self.head:
if current.data == key:
break
prev = current
current = current.next
if current == self.head:
print("Data tidak ditemukan")
return
prev.next = current.next
def sort(self):
if not self.head:
print("List kosong")
return
current = self.head
temp = None
while current.next != self.head:
temp = current.next
while temp != self.head:
if current.data > temp.data:
current.data, temp.data = temp.data, current.data
temp = temp.next
current = current.next
def find_min(self):
if not self.head:
print("List kosong")
return
current = self.head
min_value = current.data
while current.next != self.head:
current = current.next
if current.data < min_value:
min_value = current.data
return min_value
def find_max(self):
if not self.head:
print("List kosong")
return
current = self.head
max_value = current.data
while current.next != self.head:
current = current.next
if current.data > max_value:
max_value = current.data
return max_value
if __name__ == "__main__":
cll = CircularLinkedList()
while True:
print("nMenu:")
print("1. Tambah data")
print("2. Hapus data")
print("3. Tampil data")
print("4. Urutkan data")
print("5. Nilai minimum")
print("6. Nilai maksimum")
print("7. Keluar")
choice = int(input("Pilih opsi: "))
if choice == 1:
data = int(input("Masukkan data yang ingin ditambahkan: "))
cll.append(data)
elif choice == 2:
data = int(input("Masukkan data yang ingin dihapus: "))
cll.delete(data)
elif choice == 3:
cll.display()
elif choice == 4:
cll.sort()
elif choice == 5:
min_value = cll.find_min()
print(f"Nilai minimum: {min_value}")
elif choice == 6:
max_value = cll.find_max()
print(f"Nilai maksimum: {max_value}")
elif choice == 7:
break
else:
print("Opsi tidak valid")
![]() |
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team