Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Loading...
User Settings
close menu
Welcome to Scribd!
Upload
Read for free
FAQ and support
Language (EN)
Sign in
0 ratings
0% found this document useful (0 votes)
1 views
StrukturData_Pertemuan20
Uploaded by
Rafli Thio Al Harifaisyi
Copyright:
© All Rights Reserved
Available Formats
Download
as TXT, PDF, TXT or read online from Scribd
Download
Save
Save StrukturData_Pertemuan20 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
StrukturData_Pertemuan20
Uploaded by
Rafli Thio Al Harifaisyi
0 ratings
0% found this document useful (0 votes)
1 views
2 pages
Document Information
click to expand document information
Copyright
© © All Rights Reserved
Available Formats
TXT, PDF, TXT or read online from Scribd
Share this document
Share or Embed Document
Sharing Options
Share on Facebook, opens a new window
Facebook
Share on Twitter, opens a new window
Twitter
Share on LinkedIn, opens a new window
LinkedIn
Share with Email, opens mail client
Email
Copy link
Copy link
Did you find this document useful?
0%
0% found this document useful, Mark this document as useful
0%
0% found this document not useful, Mark this document as not useful
Is this content inappropriate?
Report
Copyright:
© All Rights Reserved
Available Formats
Download
as TXT, PDF, TXT or read online from Scribd
Download now
Download as txt, pdf, or txt
Save
Save StrukturData_Pertemuan20 For Later
0 ratings
0% found this document useful (0 votes)
1 views
2 pages
StrukturData_Pertemuan20
Uploaded by
Rafli Thio Al Harifaisyi
Copyright:
© All Rights Reserved
Available Formats
Download
as TXT, PDF, TXT or read online from Scribd
Save
Save StrukturData_Pertemuan20 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download as txt, pdf, or txt
Jump to Page
You are on page 1
of 2
Search inside document
Nama : Andhika Vallerian Ramadhani SantosaNIM : 231011401957Kelas
: 03TPLE018Mata Kuliah : Struktur DataTugas : Pertemuan-20
1. Kode program:
#include <iostream>#include <string>#include <limits>using namespace std;struct
Mahasiswa { long long NIM; string nama; float nilai;};struct Node {
Mahasiswa data; Node* next;};class LinkedList {private: Node* head; Node*
merge(Node* left, Node* right) { if (!left) return right; if (!right)
return left; if (left->data.NIM < right->data.NIM) { left->next =
merge(left->next, right); return left; } else { right-
>next = merge(left, right->next); return right; } } Node*
mergeSort(Node* node) { if (!node || !node->next) return node; Node*
middle = getMiddle(node); Node* nextOfMiddle = middle->next; middle-
>next = NULL; Node* left = mergeSort(node); Node* right =
mergeSort(nextOfMiddle); return merge(left, right); } Node*
getMiddle(Node* node) { if (!node) return node; Node* slow = node;
Node* fast = node->next; while (fast && fast->next) { slow =
slow->next; fast = fast->next->next; } return slow; }
void shellSort() { int size = getSize(); Node** array = new
Node*[size]; Node* current = head; for (int i = 0; i < size; ++i) {
array[i] = current; current = current->next; } for (int
gap = size / 2; gap > 0; gap /= 2) { for (int i = gap; i < size; ++i) {
Node* temp = array[i]; int j; for (j = i; j >= gap &&
array[j - gap]->data.NIM > temp->data.NIM; j -= gap) { array[j]
= array[j - gap]; } array[j] = temp; }
} for (int i = 0; i < size - 1; ++i) { array[i]->next = array[i +
1]; } array[size - 1]->next = NULL; head = array[0];
delete[] array; } int getSize() { int size = 0; Node* current =
head; while (current) { size++; current = current-
>next; } return size; }public: LinkedList() : head(NULL) {}
void insertData(const Mahasiswa& mhs) { Node* newNode = new Node{mhs, NULL};
if (!head) { head = newNode; } else { Node* temp =
head; while (temp->next) { temp = temp->next;
} temp->next = newNode; } } void displayData()
{ Node* temp = head; while (temp) { cout << "NIM: " <<
temp->data.NIM << ", Nama: " << temp->data.nama <<
", Nilai: " << temp->data.nilai << endl; temp = temp->next; }
} void sortData(int method) { if (method == 1) { head =
mergeSort(head); cout << "Data telah diurutkan menggunakan Merge Sort.\
n"; } else if (method == 2) { shellSort(); cout <<
"Data telah diurutkan menggunakan Shell Sort.\n"; } else { cout
<< "Metode pengurutan tidak valid.\n"; } }};int main() { cout <<
"Andhika Vallerian Ramadhani Santosa" << endl; cout << "231011401957" << endl <<
endl; LinkedList list; int choice; do { cout << "\nMenu:\n";
cout << "1. Insert Data Mahasiswa\n"; cout << "2. Tampilkan Data Mahasiswa\
n"; cout << "3. Urutkan Data Mahasiswa (1: Merge Sort, 2: Shell Sort)\n";
cout << "4. Keluar\n"; cout << "Pilih: "; cin >> choice; if
(cin.fail()) { cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n'); cout << "Input
tidak valid. Masukkan angka.\n"; continue; } switch
(choice) { case 1: { Mahasiswa mhs; cout
<< "Masukkan NIM: "; cin >> mhs.NIM; if (cin.fail()
|| mhs.NIM < 100000000000 || mhs.NIM > 999999999999) {
cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\
n'); cout << "NIM harus berupa 12 digit angka.\n";
break; } cin.ignore(); cout <<
"Masukkan Nama: "; getline(cin, mhs.nama); cout <<
"Masukkan Nilai: "; cin >> mhs.nilai; if (cin.fail())
{ cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n'); cout <<
"Nilai harus berupa angka.\n"; break; }
list.insertData(mhs); break; } case 2:
list.displayData(); break; case 3: { int
method; cout << "Pilih metode pengurutan (1: Merge Sort, 2: Shell
Sort): "; cin >> method; if (cin.fail()) {
cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\
n'); cout << "Input tidak valid. Masukkan angka.\n";
break; } list.sortData(method); break;
} case 4: cout << "Keluar program.\n";
break; default: cout << "Pilihan tidak valid.\n";
} } while (choice != 4); return 0;}
You might also like
Java Practical 3
Document
6 pages
Java Practical 3
Purva Tiwari
No ratings yet
labbbbbb (1)
Document
13 pages
labbbbbb (1)
Ashikur Rahman Joy
No ratings yet
shaurya ds assignment
Document
21 pages
shaurya ds assignment
Jdjdd Dkdldldk
No ratings yet
21f 9151 C ASSIGN#1
Document
20 pages
21f 9151 C ASSIGN#1
Zerry Merry
No ratings yet
Dsa Practical Questions
Document
40 pages
Dsa Practical Questions
BCA SY 63 Aaditi Ranaware
No ratings yet
Assignment 1
Document
10 pages
Assignment 1
Ahmad Sultan
No ratings yet
JFJF
Document
14 pages
JFJF
jskldf boboloko
No ratings yet
1. Ma trận
Document
32 pages
1. Ma trận
Quan Master
No ratings yet
CPP Practical
Document
25 pages
CPP Practical
sandeshdawkhar13
No ratings yet
Lab Report 2
Document
3 pages
Lab Report 2
user.sifathossain
No ratings yet
Data Structure Assignment
Document
12 pages
Data Structure Assignment
Ahmad Sultan
No ratings yet
Prelab 3
Document
7 pages
Prelab 3
phamviethungf9
No ratings yet
Task: Define Doubly Linked - Code:: "Stdafx.h"
Document
5 pages
Task: Define Doubly Linked - Code:: "Stdafx.h"
Ahmed Elsayed
No ratings yet
Code: ID: 41230100803
Document
3 pages
Code: ID: 41230100803
user.sifathossain
No ratings yet
Code
Document
3 pages
Code
user.sifathossain
No ratings yet
Lab Dsa
Document
4 pages
Lab Dsa
Safaruzzaman Shovo
No ratings yet
Bubble Sort
Document
14 pages
Bubble Sort
saadalimubarack
No ratings yet
DATA_STRUCTER_HOME_WORK[1]
Document
9 pages
DATA_STRUCTER_HOME_WORK[1]
karemanh25
No ratings yet
PROGRAM9-DSA
Document
4 pages
PROGRAM9-DSA
Rakhi Sharma
No ratings yet
PROGRAM9-DSA
Document
4 pages
PROGRAM9-DSA
asura7020
No ratings yet
Câu 1 Chương 3 Chưa Xong
Document
6 pages
Câu 1 Chương 3 Chưa Xong
Thuan Dev
No ratings yet
Data Structures and Algorithms Lab Journal - Lab 2: Objective
Document
11 pages
Data Structures and Algorithms Lab Journal - Lab 2: Objective
MZ Malik
No ratings yet
432 - Pract6-8 - Div A
Document
21 pages
432 - Pract6-8 - Div A
Kajal Goud
No ratings yet
Name Anurag Yadav STUDENT ID 202212095 M.SC It SEM-1 LAB02 1.reverse Singly List
Document
11 pages
Name Anurag Yadav STUDENT ID 202212095 M.SC It SEM-1 LAB02 1.reverse Singly List
Anurag Yadav
No ratings yet
DSL CODE 7
Document
12 pages
DSL CODE 7
fuoco414
No ratings yet
Merge Two Arrays: " - Merging Two Array'S - " "/N/Nenter No. of Elements in First Array: "
Document
21 pages
Merge Two Arrays: " - Merging Two Array'S - " "/N/Nenter No. of Elements in First Array: "
Balraj Randhawa
No ratings yet
Namespace Int Void Int Int
Document
22 pages
Namespace Int Void Int Int
infotainment
No ratings yet
Priority Queue
Document
3 pages
Priority Queue
Hamza Sajid
No ratings yet
LAB 05 - Link List 19102023 024021pm 09102024 011547pm
Document
11 pages
LAB 05 - Link List 19102023 024021pm 09102024 011547pm
abdurrehmanranjha111
No ratings yet
Vaibhavi Practical File
Document
50 pages
Vaibhavi Practical File
niasrg
No ratings yet
Fadlan Umar Rozikin-235150307111032-Teknik Komputer C - Asd Tugas 2.1
Document
10 pages
Fadlan Umar Rozikin-235150307111032-Teknik Komputer C - Asd Tugas 2.1
yt kreator
No ratings yet
Program: Singly Linked List
Document
12 pages
Program: Singly Linked List
Revathimuthusamy
No ratings yet
(Bsem-F19-200) Muhammad Muneeb
Document
23 pages
(Bsem-F19-200) Muhammad Muneeb
Muneeb Waseem
No ratings yet
TR7 - Struktur Data
Document
16 pages
TR7 - Struktur Data
jokohendra836
No ratings yet
Ihtisham Lab Assign - 2
Document
18 pages
Ihtisham Lab Assign - 2
ShAmy KhAn
No ratings yet
Linear Linked List - All Operations Included
Document
5 pages
Linear Linked List - All Operations Included
pavan raj
No ratings yet
Fadlan Umar Rozikin-235150307111032-Teknik Komputer C - Asd Tugas 2
Document
10 pages
Fadlan Umar Rozikin-235150307111032-Teknik Komputer C - Asd Tugas 2
yt kreator
No ratings yet
23536 DSA Assignment 7
Document
13 pages
23536 DSA Assignment 7
jagtapnilesh038
No ratings yet
To Check Whether The Given Linked List Is Sorted or Not
Document
5 pages
To Check Whether The Given Linked List Is Sorted or Not
Pate Vishnu
No ratings yet
Dsa Codes 1to 8
Document
44 pages
Dsa Codes 1to 8
rezzx86
No ratings yet
DSA Assignment
Document
14 pages
DSA Assignment
unknowngaming727
No ratings yet
Data Structure Record
Document
94 pages
Data Structure Record
bala
No ratings yet
DSA Lab 8
Document
7 pages
DSA Lab 8
23-20911-092
No ratings yet
File Handling With Linked List in C++
Document
3 pages
File Handling With Linked List in C++
Moiz Arif
0% (1)
Data Structure Using CPP
Document
233 pages
Data Structure Using CPP
18ITR050Naveen S
No ratings yet
DS Code
Document
20 pages
DS Code
utshashares
No ratings yet
DS Lab Assign
Document
215 pages
DS Lab Assign
sunsam098
No ratings yet
Lab Exam
Document
24 pages
Lab Exam
Shashank Sharma
No ratings yet
Data Structures
Document
28 pages
Data Structures
NehalMishra
No ratings yet
Visvesvaraya Technological University: Lab Report On Advanced Data Structures (20Cs5Peads)
Document
86 pages
Visvesvaraya Technological University: Lab Report On Advanced Data Structures (20Cs5Peads)
Sravan Dhira
No ratings yet
Data Structures Assignment - DHANANJAY SINGHAL
Document
87 pages
Data Structures Assignment - DHANANJAY SINGHAL
Shubh Sharma
No ratings yet
Lab 1-6
Document
14 pages
Lab 1-6
har08
No ratings yet
Computer Practicals-File
Document
53 pages
Computer Practicals-File
Arijit paul
No ratings yet
Linked List
Document
10 pages
Linked List
subitabhdey132
No ratings yet
Ali Irtza Haider-231259-Linked List
Document
3 pages
Ali Irtza Haider-231259-Linked List
233053
No ratings yet
DSA - Lab: Submitted To: Mam Rabia Arshad SUBMITTED BY: Muhammad Bilal
Document
8 pages
DSA - Lab: Submitted To: Mam Rabia Arshad SUBMITTED BY: Muhammad Bilal
Bilal Alone
No ratings yet
lab4
Document
13 pages
lab4
Ashikur Rahman Joy
No ratings yet
Ada Lab File
Document
26 pages
Ada Lab File
SHIVCHARAN SHARMA
No ratings yet
Data Structures With
Document
14 pages
Data Structures With
sareddysaicharanssctr
No ratings yet
LAB4
Document
14 pages
LAB4
deletednavythemarbler
No ratings yet
C++ Functions and tutorial
From Everand
C++ Functions and tutorial
Nino Paiotta
No ratings yet
Net Framework and C# Programming
Document
125 pages
Net Framework and C# Programming
Sumitesh Raj
No ratings yet
Java Exam 2011 E.C
Document
4 pages
Java Exam 2011 E.C
Magarsaa Qana'ii
No ratings yet
Program 9: Create A Database Regarding Its Indoor Patients
Document
13 pages
Program 9: Create A Database Regarding Its Indoor Patients
Neeraj Falwariya
No ratings yet
CMP 102 Introduction To CP Module 4 Software Design
Document
38 pages
CMP 102 Introduction To CP Module 4 Software Design
Miracle
No ratings yet
Assignment 6
Document
3 pages
Assignment 6
Yang Fang
No ratings yet
Series based questions
Document
25 pages
Series based questions
zubeenpaul2
No ratings yet
C++ 11 - Overview PDF
Document
61 pages
C++ 11 - Overview PDF
silly_rabbitz
No ratings yet
Inheritance Programs1
Document
3 pages
Inheritance Programs1
Dhavan Kumar
No ratings yet
Grade XI IP
Document
3 pages
Grade XI IP
Shubham Agarawal
No ratings yet
Object Oriented Programming Assignment
Document
3 pages
Object Oriented Programming Assignment
Shiva Reddy
33% (3)
Experiment 2.4: Write A Program For Employee Management System
Document
3 pages
Experiment 2.4: Write A Program For Employee Management System
Lovelesh Kumar
No ratings yet
SE Question Bank New Course - 1 Oct 2020
Document
8 pages
SE Question Bank New Course - 1 Oct 2020
IRRITATED OP
No ratings yet
HND-OOP Assignment
Document
25 pages
HND-OOP Assignment
Sandhya Paudel
100% (2)
Java - Date, Time
Document
8 pages
Java - Date, Time
ahmed storage
No ratings yet
HAL Interface Definition Language or HIDL
Document
9 pages
HAL Interface Definition Language or HIDL
Sanjay Patel
100% (1)
4-C - Advanced
Document
32 pages
4-C - Advanced
Just9day
No ratings yet
Riphah International University I-14 Main Campus Faculty of Computing
Document
2 pages
Riphah International University I-14 Main Campus Faculty of Computing
Rafay Kazmi
No ratings yet
Lab 5
Document
5 pages
Lab 5
LAVANYA M CSE
No ratings yet
OOPS Unit 2
Document
66 pages
OOPS Unit 2
Chandru
No ratings yet
C 21
Document
1 page
C 21
susvi85
No ratings yet
Variables
Document
11 pages
Variables
revathi
No ratings yet
Cell Color in ABAP ALV Grid Report
Document
18 pages
Cell Color in ABAP ALV Grid Report
viceawork01
No ratings yet
Getting Into Javascript PDF
Document
96 pages
Getting Into Javascript PDF
ictsufian
No ratings yet
Inheritance: (A) Single-Level Inheritance
Document
3 pages
Inheritance: (A) Single-Level Inheritance
snehachandan91
No ratings yet
CBT Lab Final Soft
Document
50 pages
CBT Lab Final Soft
pathry_r
No ratings yet
Object Oriented Analysis
Document
43 pages
Object Oriented Analysis
Abdela Aman Mtech
No ratings yet
C, C++ Questions: Ans. B
Document
14 pages
C, C++ Questions: Ans. B
kmbkris
No ratings yet
Typescript Cheat Sheet: by Via
Document
2 pages
Typescript Cheat Sheet: by Via
pbecic
No ratings yet
Faq C++ Isocpp
Document
448 pages
Faq C++ Isocpp
ONDOUA KOUDA ZEH Hervé Maurice
No ratings yet