Ada banyak operasi yang dapat dilakukan pada Daftar Tertaut, seperti operasi penyisipan di mana kita dapat menambahkan simpul baru ke daftar tertaut yang sudah ada, operasi penghapusan di mana kita dapat menghapus simpul dari daftar tertaut, dan menampilkan data yang ada
Dalam daftar tertaut tunggal, simpul dari daftar tertaut tunggal menunjuk ke alamat lokasi memori tempat simpul berikutnya disimpan. Demikian pula, dengan cara ini, semua node menyimpan alamat node berikutnya masing-masing. Selain simpul terakhir, alamat di penunjuk simpul terakhir adalah NULL yang mewakili simpul terakhir dari daftar tertaut
Ada satu lagi operasi yang didukung oleh Linked List yaitu operasi putar. Dalam operasi ini, simpul utama dari daftar tertaut dipindahkan ke elemen terakhir dari Daftar Tertaut, dan elemen pertama dari Daftar Tertaut menjadi elemen terakhir yang ada di Daftar Tertaut
Kode C
Sekarang mari kita lihat kode merotasi atau membalikkan daftar tertaut dalam berbagai bahasa pemrograman
Keluaran
Kode di atas memberikan output berikut
Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 15 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 13 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 11 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 10 Please enter a valid option from the menu to proceed further. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 5 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 3 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 2 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 1 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 3 Data in the Linked List is: 1 2 3 5 11 13 15 Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 2 Linked List Rotated Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 3 Data in the Linked List is: 15 13 11 5 3 2 1 Type [N or n] to terminate the program. Type [Y or y] to continue the program. N
Kode C++
Sekarang mari kita lihat kode C++ untuk merotasi atau membalikkan linked list
Keluaran
Kode C++ ini memberikan output berikut,
Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 190 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 70 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 55 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 40 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 30 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 20 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 10 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 3 Data in the Linked List is: 10 20 30 40 55 70 190 Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 2 Linked List Rotated Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 3 Data in the Linked List is: 190 70 55 40 30 20 10 Type [N or n] to terminate the program. Type [Y or y] to continue the program. N _
Kode Jawa
Sekarang mari kita lihat kode Java untuk merotasi atau membalikkan linked list
Keluaran
Kode java di atas memberikan output berikut,
Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 1 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 2 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 3 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 4 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 5 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 1 Enter the data that you want to add to the newly added node to the Linked List: 6 Data Added Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 3 Data in the Linked List is: 1 2 3 4 5 6 Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 2 Linked List Rotated Successfully. Type [N or n] to terminate the program. Type [Y or y] to continue the program. y Please Choose one of the Operations:: 1. To Insert Data in the Linked List. 2. To Rotate the Linked List. 3. To Display Data present in the Linked List. 3 Data in the Linked List is: 6 5 4 3 2 1 Type [N or n] to terminate the program. Type [Y or y] to continue the program. N
Jadi, dalam artikel ini, kami mendapat gambaran yang jelas tentang operasi rotasi dalam daftar tertaut. Kami juga melihat cara menulis kode operasi putar di daftar tertaut dalam berbagai bahasa pemrograman seperti C, C++, dan Java