-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq2.4.cpp
More file actions
41 lines (31 loc) · 834 Bytes
/
q2.4.cpp
File metadata and controls
41 lines (31 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "common_header.hpp"
#include <iostream>
#include <vector>
using namespace std;
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv) {
vector<int> data{3, 5, 8, 5, 10, 2, 1};
int partition = 8, swap = 0;
myspace::SingleLL *head = myspace::generateSingleLL(&data);
cout << "original linked list: \n";
myspace::printSingleLL(head);
myspace::SingleLL *ptr1, *ptr2;
ptr1 = head;
ptr2 = head->next;
while (ptr1->data < partition) {
ptr1 = ptr2;
ptr2 = ptr2->next;
}
while (ptr2 != NULL) {
if (ptr2->data < partition) {
swap = ptr1->data;
ptr1->data = ptr2->data;
ptr2->data = swap;
ptr1 = ptr1->next;
ptr2 = ptr2->next;
} else
ptr2 = ptr2->next;
}
cout << "modified linked list: \n";
myspace::printSingleLL(head);
return 0;
}