From 431217a7dbe9077f362ee2ce5cc018d1b9b5f737 Mon Sep 17 00:00:00 2001 From: PRANESH GUPTA <46838529+pranesh6876@users.noreply.github.com> Date: Mon, 4 Oct 2021 00:13:54 +0530 Subject: [PATCH] Create 59.cpp --- C++/59.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 C++/59.cpp diff --git a/C++/59.cpp b/C++/59.cpp new file mode 100644 index 0000000..e4263d3 --- /dev/null +++ b/C++/59.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +int main() +{ + string str[10], temp; + + cout << "Enter 10 words: " << endl; + for(int i = 0; i < 10; ++i) + { + getline(cin, str[i]); + } + + // Use Bubble Sort to arrange words + for (int i = 0; i < 9; ++i) { + for (int j = 0; j < 9 - i; ++j) { + if (str[j] > str[j + 1]) { + temp = str[j]; + str[j] = str[j + 1]; + str[j + 1] = temp; + } + } + } + + cout << "In lexicographical order: " << endl; + + for(int i = 0; i < 10; ++i) + { + cout << str[i] << endl; + } + return 0; +}