SlideShare a Scribd company logo
1 of 4
#include <iostream>
#include <string>
#include <fstream>
#include <cassert>
using namespace std;
// Ali Ülkü 13945 - This program takes input file with mixed numbers from user
// and sort them using bubble sort algorithm
struct LinkedList //LinkedList is a user given name
{
int num;
LinkedList *next; // pointer for the
next node
LinkedList () //default constructor
:num(0), next(NULL)
{}
LinkedList (int i,LinkedList *n) //constructor
:num(i), next(n)
{}
};
LinkedList *quickSort(int *array, int startPosition, int endPosition)
{
int n = endPosition - 1;
int middle = (startPosition+endPosition)/2;
int pivot = array[middle];
int* temp = new int[n]; // Temp is an array which contains mixed numbers
int variable = 0;
int i = startPosition;
int j = endPosition;
while (startPosition < j || i< endPosition )
{
while (array[i] < pivot)
i++;
while (array[j] > pivot)
j--;
if (i <= j) {
variable = array[i];
array[i] = array[j];
array[j] = variable;
i++;
j--;
}
/* recursion */
if (startPosition < j)
{
quickSort(array, startPosition, j);
}
if (i < endPosition)
{
quickSort(array, i, endPosition);
}
LinkedList * quick = new LinkedList;
quick->num = array[0];
LinkedList * head = quick;
int counter = 1; // Counter starts from 1 since i starts
from 1
for(int i = 1; i < n+2; i++)
{
quick->next = new LinkedList; // new LinkedList is
allocated from the memory whose adress is pointed by "sorting"
quick= quick->next; // After each cycle,
sorting shows a new sorting
quick->num =array[i]; // Num will takes the
value of sorted array
counter++; // to provide
true condition for assert() till last "sorting"
}
quick->next= NULL; // Last "sorting"
should point NULL since there is no need for another "sorting"
return head;
}
}
LinkedList *bubbleSort(int *array, int size)
{
int* temp = new int[size]; // Temp is an array which contains mixed
numbers
for(int i = 0; i <size; i++)
{
temp[i] = array[i]; // Temp is pushed by the elements of input
array.
}
for (int i=0; i < size-1; i++)
{
for(int j = i+1; j < size; j++)
{
if(temp[i]>temp[j])
{
int var = temp[i]; // if certain number is greater
temp[i] = temp[j]; // than following compared
number,
temp[j] = var; // they will switch place
}
}
}
LinkedList * sorting = new LinkedList;
sorting->num = temp[0];
LinkedList * head = sorting;
int counter = 1; // Counter starts from 1 since i starts
from 1
for(int i = 1; i < size; i++)
{
sorting->next = new LinkedList; // new LinkedList is
allocated from the memory whose adress is pointed by "sorting"
sorting = sorting->next; // After each cycle,
sorting shows a new sorting
sorting->num = temp[i]; // Num will takes the
value of sorted array
counter++; // to provide
true condition for assert() till last "sorting"
}
assert(size == counter);
sorting->next= NULL; // Last "sorting"
should point NULL since there is no need for another "sorting"
return head; // Returns to
the "head" which equals to "sorting"
}
int main()
{
ifstream file;
string filename = "HW2014-2015-Summer02-Input.txt";
file.open(filename.c_str());
string line = "";
int countOfLines = 0;
while(getline(file,line)) //Read the file in order to obtain the
number of lines
{
countOfLines++; //The size of the myList array
}
int endPosition = countOfLines - 1;
int startPosition = 0;
int* myList = new int[countOfLines]; //Creating a dynamic array
file.clear(); //To read the
file from the beginning
file.seekg(0, ios::beg);
int index = 0;
while(getline(file,line)) // Reads the file
from beggining, pushes elements in MyList array
{
myList[index]=stoi(line); // Read lines must be
converted from string to the integer since numbers of elements will be compared
index++;
}
LinkedList* temp1 = quickSort(myList,startPosition, endPosition);
// Calls the LinkedLink function called "bubbleSort(int* array, int
size)
LinkedList* temp2 = bubbleSort(myList,countOfLines); // Calls
the LinkedLink function called "bubbleSort(int* array, int size)
ofstream myfile;
myfile.open ("HW2014-2015-Summer02-Output.txt");
myfile << "quickSort"<<endl;
while(temp1 != NULL)
{
myfile << temp1->num << endl;
temp1 = temp1->next;
}
myfile << endl << "bubbleSort"<<endl;
while(temp2 != NULL)
{
myfile << temp2->num << endl;
temp2 = temp2->next;
}
myfile.close();
cin.get();
cin.ignore();
return 0;
}

More Related Content

What's hot

2.2 higher order-functions
2.2 higher order-functions2.2 higher order-functions
2.2 higher order-functions
futurespective
 

What's hot (20)

Link list
Link listLink list
Link list
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Stacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti AroraStacks & Queues By Ms. Niti Arora
Stacks & Queues By Ms. Niti Arora
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
2.2 higher order-functions
2.2 higher order-functions2.2 higher order-functions
2.2 higher order-functions
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Stacks, Queues, Deques
Stacks, Queues, DequesStacks, Queues, Deques
Stacks, Queues, Deques
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURES
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
C# Loops
C# LoopsC# Loops
C# Loops
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Address calculation-sort
Address calculation-sortAddress calculation-sort
Address calculation-sort
 
Queue
QueueQueue
Queue
 

Viewers also liked

Tanggung jawab perusahaan
Tanggung jawab perusahaanTanggung jawab perusahaan
Tanggung jawab perusahaan
marianenza
 
Final ppt ens492
Final ppt ens492Final ppt ens492
Final ppt ens492
Ali Ülkü
 
Makalah Aderina Chemonk: Abu Yazid Al-Bustomi
Makalah Aderina Chemonk: Abu Yazid Al-BustomiMakalah Aderina Chemonk: Abu Yazid Al-Bustomi
Makalah Aderina Chemonk: Abu Yazid Al-Bustomi
Ali Hanafiah
 
PSIKOTERAPI: TERAPI FEMINIS
PSIKOTERAPI: TERAPI FEMINISPSIKOTERAPI: TERAPI FEMINIS
PSIKOTERAPI: TERAPI FEMINIS
Ali Hanafiah
 

Viewers also liked (16)

Iklan
IklanIklan
Iklan
 
Tanggung jawab perusahaan
Tanggung jawab perusahaanTanggung jawab perusahaan
Tanggung jawab perusahaan
 
Final ppt ens492
Final ppt ens492Final ppt ens492
Final ppt ens492
 
Lean UX Basics - UX Meetup #9 UniteUX
Lean UX Basics - UX Meetup #9 UniteUXLean UX Basics - UX Meetup #9 UniteUX
Lean UX Basics - UX Meetup #9 UniteUX
 
User Experience (UX) View Tips
User Experience (UX) View TipsUser Experience (UX) View Tips
User Experience (UX) View Tips
 
Cuss Hajar! - UX Meetup #9 UniteUX
Cuss Hajar! - UX Meetup #9 UniteUXCuss Hajar! - UX Meetup #9 UniteUX
Cuss Hajar! - UX Meetup #9 UniteUX
 
Makalah Aderina Chemonk: Abu Yazid Al-Bustomi
Makalah Aderina Chemonk: Abu Yazid Al-BustomiMakalah Aderina Chemonk: Abu Yazid Al-Bustomi
Makalah Aderina Chemonk: Abu Yazid Al-Bustomi
 
Chapter 4, Conceptualizing A Research Study
Chapter 4, Conceptualizing A Research StudyChapter 4, Conceptualizing A Research Study
Chapter 4, Conceptualizing A Research Study
 
Panduan Penyelesaian SKU Penegak
Panduan Penyelesaian SKU PenegakPanduan Penyelesaian SKU Penegak
Panduan Penyelesaian SKU Penegak
 
Final ppt ens492
Final ppt ens492Final ppt ens492
Final ppt ens492
 
PSIKOTERAPI: TERAPI FEMINIS
PSIKOTERAPI: TERAPI FEMINISPSIKOTERAPI: TERAPI FEMINIS
PSIKOTERAPI: TERAPI FEMINIS
 
Chapter 3, The Spanish Period
Chapter 3, The Spanish PeriodChapter 3, The Spanish Period
Chapter 3, The Spanish Period
 
The craft of political research, chapter 1
The craft of political research, chapter 1The craft of political research, chapter 1
The craft of political research, chapter 1
 
Major Breakthrough Inventions for Injection Molding
Major Breakthrough Inventions for Injection MoldingMajor Breakthrough Inventions for Injection Molding
Major Breakthrough Inventions for Injection Molding
 
Ralph Lauren Digital Strategy Campaign
Ralph Lauren Digital Strategy CampaignRalph Lauren Digital Strategy Campaign
Ralph Lauren Digital Strategy Campaign
 
Article VI: Legislative Department
Article VI: Legislative DepartmentArticle VI: Legislative Department
Article VI: Legislative Department
 

Similar to Hw3

#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
KUNALHARCHANDANI1
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
ankit11134
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
pasqualealvarez467
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
forladies
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
flashfashioncasualwe
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
JUSTSTYLISH3B2MOHALI
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
arorastores
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
arri2009av
 
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfI keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
arkmuzikllc
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Implement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdf
arihantstoneart
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
fastechsrv
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
anupambedcovers
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
afgt2012
 

Similar to Hw3 (20)

#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
DS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docxDS UNIT4_OTHER LIST STRUCTURES.docx
DS UNIT4_OTHER LIST STRUCTURES.docx
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
–PLS write program in c++Recursive Linked List OperationsWrite a.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
DAA Lab Work.docx
DAA Lab Work.docxDAA Lab Work.docx
DAA Lab Work.docx
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfI keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
 
Implement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdf
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
 

Recently uploaded

Simple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptxSimple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptx
balqisyamutia
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
ehyxf
 
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
awasv46j
 
cholilithiasis, cholecystitis,gall bladdder .pdf
cholilithiasis, cholecystitis,gall bladdder .pdfcholilithiasis, cholecystitis,gall bladdder .pdf
cholilithiasis, cholecystitis,gall bladdder .pdf
RawalRafiqLeghari
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
instagramfab782445
 
Minimalist Orange Portfolio by Slidesgo.pptx
Minimalist Orange Portfolio by Slidesgo.pptxMinimalist Orange Portfolio by Slidesgo.pptx
Minimalist Orange Portfolio by Slidesgo.pptx
balqisyamutia
 
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
HyderabadDolls
 
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
nirzagarg
 

Recently uploaded (20)

Sweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptxSweety Planet Packaging Design Process Book.pptx
Sweety Planet Packaging Design Process Book.pptx
 
Simple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptxSimple Conference Style Presentation by Slidesgo.pptx
Simple Conference Style Presentation by Slidesgo.pptx
 
How to Create a Productive Workspace Trends and Tips.pdf
How to Create a Productive Workspace Trends and Tips.pdfHow to Create a Productive Workspace Trends and Tips.pdf
How to Create a Productive Workspace Trends and Tips.pdf
 
Dahisar Comfortable Call Girls ,09167354423,Mira Road Model Call Girls
Dahisar Comfortable Call Girls ,09167354423,Mira Road Model Call GirlsDahisar Comfortable Call Girls ,09167354423,Mira Road Model Call Girls
Dahisar Comfortable Call Girls ,09167354423,Mira Road Model Call Girls
 
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for FriendshipRaebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
Raebareli Girl Whatsapp Number 📞 8617370543 | Girls Number for Friendship
 
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
怎样办理莫纳什大学毕业证(Monash毕业证书)成绩单留信认证
 
Hackathon evaluation template_latest_uploadpdf
Hackathon evaluation template_latest_uploadpdfHackathon evaluation template_latest_uploadpdf
Hackathon evaluation template_latest_uploadpdf
 
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
一比一原版(WLU毕业证)罗瑞尔大学毕业证成绩单留信学历认证原版一模一样
 
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
NO1 Top Pakistani Amil Baba Real Amil baba In Pakistan Najoomi Baba in Pakist...
 
cholilithiasis, cholecystitis,gall bladdder .pdf
cholilithiasis, cholecystitis,gall bladdder .pdfcholilithiasis, cholecystitis,gall bladdder .pdf
cholilithiasis, cholecystitis,gall bladdder .pdf
 
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
Abortion pill for sale in Muscat (+918761049707)) Get Cytotec Cash on deliver...
 
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best ServiceHigh Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
High Profile Escorts Nerul WhatsApp +91-9930687706, Best Service
 
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
Just Call Vip call girls Fatehpur Escorts ☎️8617370543 Two shot with one girl...
 
❤️ Call Girls Service Amritsar Call Girls (Adult Only) 💯Call Us 🔝 6378878445 ...
❤️ Call Girls Service Amritsar Call Girls (Adult Only) 💯Call Us 🔝 6378878445 ...❤️ Call Girls Service Amritsar Call Girls (Adult Only) 💯Call Us 🔝 6378878445 ...
❤️ Call Girls Service Amritsar Call Girls (Adult Only) 💯Call Us 🔝 6378878445 ...
 
Essential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive GuideEssential UI/UX Design Principles: A Comprehensive Guide
Essential UI/UX Design Principles: A Comprehensive Guide
 
Minimalist Orange Portfolio by Slidesgo.pptx
Minimalist Orange Portfolio by Slidesgo.pptxMinimalist Orange Portfolio by Slidesgo.pptx
Minimalist Orange Portfolio by Slidesgo.pptx
 
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
Madhyamgram \ (Genuine) Escort Service Kolkata | Service-oriented sexy call g...
 
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In Sonipat [ 7014168258 ] Call Me For Genuine Models W...
 
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
Abortion pills in Riyadh +966572737505 <> buy cytotec <> unwanted kit Saudi A...
 
Independent Escorts Goregaon WhatsApp +91-9930687706, Best Service
Independent Escorts Goregaon WhatsApp +91-9930687706, Best ServiceIndependent Escorts Goregaon WhatsApp +91-9930687706, Best Service
Independent Escorts Goregaon WhatsApp +91-9930687706, Best Service
 

Hw3

  • 1. #include <iostream> #include <string> #include <fstream> #include <cassert> using namespace std; // Ali Ülkü 13945 - This program takes input file with mixed numbers from user // and sort them using bubble sort algorithm struct LinkedList //LinkedList is a user given name { int num; LinkedList *next; // pointer for the next node LinkedList () //default constructor :num(0), next(NULL) {} LinkedList (int i,LinkedList *n) //constructor :num(i), next(n) {} }; LinkedList *quickSort(int *array, int startPosition, int endPosition) { int n = endPosition - 1; int middle = (startPosition+endPosition)/2; int pivot = array[middle]; int* temp = new int[n]; // Temp is an array which contains mixed numbers int variable = 0; int i = startPosition; int j = endPosition; while (startPosition < j || i< endPosition ) { while (array[i] < pivot) i++; while (array[j] > pivot) j--; if (i <= j) { variable = array[i]; array[i] = array[j]; array[j] = variable; i++; j--; } /* recursion */ if (startPosition < j) { quickSort(array, startPosition, j); } if (i < endPosition) { quickSort(array, i, endPosition); }
  • 2. LinkedList * quick = new LinkedList; quick->num = array[0]; LinkedList * head = quick; int counter = 1; // Counter starts from 1 since i starts from 1 for(int i = 1; i < n+2; i++) { quick->next = new LinkedList; // new LinkedList is allocated from the memory whose adress is pointed by "sorting" quick= quick->next; // After each cycle, sorting shows a new sorting quick->num =array[i]; // Num will takes the value of sorted array counter++; // to provide true condition for assert() till last "sorting" } quick->next= NULL; // Last "sorting" should point NULL since there is no need for another "sorting" return head; } } LinkedList *bubbleSort(int *array, int size) { int* temp = new int[size]; // Temp is an array which contains mixed numbers for(int i = 0; i <size; i++) { temp[i] = array[i]; // Temp is pushed by the elements of input array. } for (int i=0; i < size-1; i++) { for(int j = i+1; j < size; j++) { if(temp[i]>temp[j]) { int var = temp[i]; // if certain number is greater temp[i] = temp[j]; // than following compared number, temp[j] = var; // they will switch place } } } LinkedList * sorting = new LinkedList; sorting->num = temp[0]; LinkedList * head = sorting; int counter = 1; // Counter starts from 1 since i starts from 1 for(int i = 1; i < size; i++) { sorting->next = new LinkedList; // new LinkedList is allocated from the memory whose adress is pointed by "sorting" sorting = sorting->next; // After each cycle, sorting shows a new sorting sorting->num = temp[i]; // Num will takes the value of sorted array counter++; // to provide true condition for assert() till last "sorting" } assert(size == counter); sorting->next= NULL; // Last "sorting"
  • 3. should point NULL since there is no need for another "sorting" return head; // Returns to the "head" which equals to "sorting" } int main() { ifstream file; string filename = "HW2014-2015-Summer02-Input.txt"; file.open(filename.c_str()); string line = ""; int countOfLines = 0; while(getline(file,line)) //Read the file in order to obtain the number of lines { countOfLines++; //The size of the myList array } int endPosition = countOfLines - 1; int startPosition = 0; int* myList = new int[countOfLines]; //Creating a dynamic array file.clear(); //To read the file from the beginning file.seekg(0, ios::beg); int index = 0; while(getline(file,line)) // Reads the file from beggining, pushes elements in MyList array { myList[index]=stoi(line); // Read lines must be converted from string to the integer since numbers of elements will be compared index++; } LinkedList* temp1 = quickSort(myList,startPosition, endPosition); // Calls the LinkedLink function called "bubbleSort(int* array, int size) LinkedList* temp2 = bubbleSort(myList,countOfLines); // Calls the LinkedLink function called "bubbleSort(int* array, int size) ofstream myfile; myfile.open ("HW2014-2015-Summer02-Output.txt"); myfile << "quickSort"<<endl; while(temp1 != NULL) { myfile << temp1->num << endl; temp1 = temp1->next; } myfile << endl << "bubbleSort"<<endl; while(temp2 != NULL) { myfile << temp2->num << endl; temp2 = temp2->next; } myfile.close();