SlideShare a Scribd company logo
1 of 12
#include "stdafx.h"
using namespace std;
#include <stdlib.h>
#include <math.h>
#include <fstream>
void quicksort(int [], int , int, int& );
void swap(int &, int &);
int insertionSort(int [], int, int);
// *** FOR ONLINE DATA STRUCTURES COURSE ****
11/19/11
// ******* STUDENTS -- GO TO THE mymain FUNCTION
AND READ THE COMMENTS. DO NOT MODIFY ANY CODE
OTHER THAN THE TWO FUNCTIONS YOU HAVE TO
WRITE *******
int insertion_style_sort(int data[], int len, int a[], int limit)
{
// general insertion sort which uses increments you supply
// can be used to perform Sedgewick, Hibbard, 531 and Shell
sorts (or with any increments)
// data[] this is the data to sort
// len number of elements in data to sort
// a[] increments to use for sorting (highest first, last
increment is always 1).
// limit number of increments
int counter=0, gap, i, j, temp;
for(int k = limit; k >= 0; k--)
{
gap = a[k];
for( i = gap; i < len; i++)
{
temp = data[i];
counter++;
for( j = i; j >=gap && temp < data[j - gap]; j-=gap)
{
data[j] = data[ j - gap];
counter++;
}
data[j] = temp;
}
if(gap == 1)break;
}
return counter; // return the number of operations performed
}
int insertionSort(int data[], int start, int stop)
{
int count;
int a[2];
a[0] = 1;// create the increments (which are just 1)
a[1] = 1;
count = insertion_style_sort(data, stop - start, a, 1);
return count;
}
int shellsort_Shellincrements(int data[], int len)
{// this code is taken from the Weiss text
int j=0, limit, temp, counter=0;
int *a = new int[len/2];
limit = j = log10((double)len)/log10(2.);
// create Shell's increments
for(int gap = len/2; gap > 0; gap /= 2)
{
a[j--] = gap;
}
counter = insertion_style_sort(data, len, a, limit);
return counter;
}
int shellsort_531increments(int data[], int len)
{// this code is taken from the Weiss text and demonstrates the
example on p 257 using this set of increments
int a[]={1, 1, 3, 5}; // this was wrong in the code on the Bb
int counter = insertion_style_sort(data, len, a, 3);
return counter;
}
int shellsort_Hibbardsincrements(int data[], int len)
{// this code is taken from the Weiss text and demonstrates the
example on p 257 using this set of increments
int *a;
double x = len;
x = log10(x)/log10(2.);
int ix = (int)x;
// create the increments for Hibbard
a = new int[ix+1];
for(int k = ix; k >= 1; k--)
a[k] = (int)pow(2., (double)k) - 1;
a[0]= 1;
int counter = insertion_style_sort(data, len, a, ix);
delete [] a;
return counter;
}
int shellsort_Sedgewicksincrements(int data[], int len)
{// this code is taken from the Weiss text and demonstrates the
example on p 257 using this set of increments
// I added the code to create the increments
int i, j, temp, gap, counter=1;// don't return zero
double x, y;
i = 0;
//Compute the increment sequence for this size sample (len)
while(true) // solve for i, 9 * 4^i - 9 * 2^i + 1 = len
{
if( (j=(9*(int)pow(4., i) - 9*(int)pow(2., i) + 1)) >
len)break;
i++;
}
x = i;
i = 0;
while( true) // solve for i, 4^i - 3 * 2^i + 1 = len
{
if( (j=((int)pow(4., i) - 3*(int)pow(2., i) + 1)) > len)break;
i++;
}
y = i;
if(y > x)x = y; // take the larger of the two
int ix = (int)x;
int *a = new int[2*ix+2];// create an array to hold the
increments
for(i = 0; i < ix; i++)
{ // create the increments
a[2*i] = (int)(9*(pow(4., (double)i) - pow(2., (double)i)) + 1);
a[2*i+1] = (int)(pow(4., (double)i) - 3.*pow(2., (double)i) + 1);
if(a[2*i+1] < 1)a[2*i+1] = 1;
}
insertionSort(a, 0, 2*ix-1);// sort the increments in descending
order
int limit = 2*ix-1;
// perform the insertion style sort on the data with these
increments
counter = insertion_style_sort(data, len, a, 2*ix-1);
return counter;
}
// ***************** EXAMPLE FUNCTION - use this to see
how to write the two functions below, but use your own
increment strategy
*****************************************************
******
int shellsort_Rootsincrements(int data[], int len)
{ // made up by DJF to show how to create and test your own
algorithm
// for this strategy, use 5 increments consisting of the following
roots of len, 1/2, 1/3, 1/4, 1/5
int *a;
int ix = 5;
int j=2;// start at the square root (it is the largest increment)
a = new int[ix+1];
a[0] = 1; // last increment must always be 1 else you won't get
a complete sort
// increments must be in descending order (largest to
smallest, with 1 being the last increment)
for(int k = ix; k >= 1; k--)
a[k] = (int)pow((double)len, (double)1/(double)(j++));
int counter = insertion_style_sort(data, len, a, ix); // leave
this code in place
delete [] a;
return counter;
}
//
*****************************************************
***********************
// ***************** YOUR FUNCTION - YOU WRITE THIS
(this is a copy of the shellsort_Rootsincrements that you can
modify
*****************************************************
******
int shellsort_yyyincrements(int data[], int len)
{
int *a;
int ix = 5;
int j=2;// start at the square root (it is the largest
increment)
a = new int[ix+1];
a[0] = 1; // last increment must always be 1 else you
won't get a complete sort
// increments must be in descending order (largest to
smallest, with 1 being the last increment (stored at location a[0]
)
for(int k = ix; k >= 1; k--)
a[k] = (int)pow((double)len,
(double)1/(double)(j++));
int counter = insertion_style_sort(data, len, a, ix); // leave
this code in place
delete [] a;
return counter;
}
//
*****************************************************
***********************
// ***************** YOUR FUNCTION - YOU WRITE THIS
(this is a copy of the shellsort_Rootsincrements that you can
modify
*****************************************************
******
int shellsort_zzzincrements(int data[], int len)
{
int *a;
int ix = 5;
int j=2;// start at the square root (it is the largest
increment)
a = new int[ix+1];
a[0] = 1; // last increment must always be 1 else you
won't get a complete sort
// increments must be in descending order (largest to
smallest, with 1 being the last increment (stored at location a[0]
)
for(int k = ix; k >= 1; k--)
a[k] = (int)pow((double)len,
(double)1/(double)(j++));
int counter = insertion_style_sort(data, len, a, ix);
delete [] a;
return counter;
}
//
*****************************************************
***********************
void mycopy(int source[], int dest[], int n)
{
for(int i=0; i < n; i++)dest[i] = source[i];
}
void gendata(int array[], int length, int modulus, int base)
{
for(int i=0; i < length; i++)
array[i] = rand()%modulus + base;
}
int mymain() // don't modify this code
{
//
*****************************************************
*********
// file format for exporting graphs to DSWB
//Number of curves (int) (blank) Number of points in a curve
(must be 15)
//Graph Title (char string)
//Curve Labels (char string with | delimiter)
//X axis label (char string)
//Y axis label (char string)
// Showcurves (char string)
// Scalecurves (char string)
// Graph style (char string -> loglog, loglinear, linearlog,
linearlinear)
// X points (one line, 15 points)
// Y points for curve #1 (one line, 15 points)
// Y points for curve #2
// Y points for curve #3
//....
//....
// Y points for curve 11
//
*****************************************************
***********
int *data, *save; // arrays to hold data to be sorted, and also to
back it up
int counts [10] [15]; // results of sorts (counts) saved for
graphing
ofstream fpout; // file stream for data file to be read by
sdiapp.exe
// ofstream fpout1; // file stream for sorted output to be used
while debugging the code
fpout.open("edit1.txt");// name this file so sdiapp.exe will
open without you having to type name
if(fpout.fail()) // did the file open?
{
cout << "Data file (data) did not open";
system("pause");
exit(0);
}
// uncomment this code if you want to write output sorted data
//fpout1.open("output.txt");
//if(fpout1.fail())
//{
// cout << "Data file (output) did not open";
// system("pause");
// exit(0);
//}
int nc = 8; // This is the number of curves including your 3.
int np = 15; // This stays at 15 to be compatible with the DSWB
fpout << nc << " " << np << endl; // number of curves (nc) and
number of points/curve (np)
fpout << "Sort Increments" << endl; // graph title
fpout <<
"Shell|Hibbard|Sedgewick|Roots|My2|My3|531|Increment| " <<
endl; // curve labels
fpout << "Sample Size(N)" << endl; // Horizontal axis title
fpout << "Operations" << endl; // Vertical axis title
fpout << "01234567890" << endl;// you don't need to change
this
fpout << "01234567890" << endl;// you don't need to change
this
fpout << "loglog" << endl; // can be loglog, loglinear,
linearlog, linearlinear (upper of lower case)
int samples[15] = {8, 16, 32, 48, 64, 96, 128, 256, 512, 1024,
2048, 3072, 4096, 8192, 16384};
for(int i = 0; i < 10; i++) // set the counts arrays to 1 (because
your routines are not written yet)
for(int j=0; j < 15; j++)
counts[i][j] = 1; // use 1 instead of zero because log plots
won't work with a zero
// generate 15 data points for each curve
int N;
for(int i = 0; i < 15; i++)
{
N = samples[i]; // get the sample size
data = new int[N]; // allocate storage
save = new int[N];
gendata(data, N, RAND_MAX, 0); // generate the data
mycopy(data, save, N); // save the dat for restore, else you will
be sorting data already sorted
counts[0][i] = shellsort_Shellincrements(data, N);// call each
routine and capture it's count
mycopy(save, data, N);// restore to the unsorted state for the
next routine
counts[1][i] = shellsort_Hibbardsincrements(data, N);
mycopy(save, data, N);
counts[2][i] = shellsort_Sedgewicksincrements(data, N);
mycopy(save, data, N);
counts[3][i] = shellsort_Rootsincrements(data, N); // here is an
an example, I an using the roots of N
mycopy(save, data, N);
counts[4][i] = shellsort_yyyincrements(data, N);
mycopy(save, data, N);
counts[5][i] = shellsort_zzzincrements(data, N);
mycopy(save, data, N);
// other reference curves -
counts[6][i] = shellsort_531increments(da ta, N);
mycopy(save, data, N);
counts[7][i] = insertionSort(data, 0, N-1);
mycopy(save, data, N);
delete [] data;
}
for(int i = 0; i < 15; i++)
{ // write independent data on the first line
fpout << samples[i] << " ";
}
fpout << endl;
for(int i=0; i < nc; i++)
{
for(int k = 0; k < 15; k++)
{
fpout << counts[i][k] << " ";
}
fpout << endl;
}
fpout.close();
// fpout1.close(); // uncomment if you use fpout1
return 0;
}
Solution
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[30];
int i,j,k,tmp,num;
printf("Enter total no. of elements : ");
scanf("%d", &num);
for(k=0; k<num; k++)
{
printf(" Enter %d number : ",k+1);
scanf("%d",&arr[k]);
}
for(i=num/2; i>0; i=i/2)
{
for(j=i; j<num; j++)
{
for(k=j-i; k>=0; k=k-i)
{
if(arr[k+i]>=arr[k])
break;
else
{
tmp=arr[k];
arr[k]=arr[k+i];
arr[k+i]=tmp;
}
}
}
}
printf("t**** Shell Sorting **** ");
for(k=0; k<num; k++)
printf("%dt",arr[k]);
getch();
return 0;
}

More Related Content

Similar to #include stdafx.h using namespace std; #include stdlib.h.docx

operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfaptcomputerzone
 
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.pdfyamew16788
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...GkhanGirgin3
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
 
how to reuse code
how to reuse codehow to reuse code
how to reuse codejleed1
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdffeelinggifts
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012Connor McDonald
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfaquazac
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfmichardsonkhaicarr37
 
Let’s talk about microbenchmarking
Let’s talk about microbenchmarkingLet’s talk about microbenchmarking
Let’s talk about microbenchmarkingAndrey Akinshin
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docxjosies1
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyondFrancis Johny
 

Similar to #include stdafx.h using namespace std; #include stdlib.h.docx (20)

DAA Lab Work.docx
DAA Lab Work.docxDAA Lab Work.docx
DAA Lab Work.docx
 
operating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.pdfoperating system ubuntu,linux,MacProgram will work only if you g.pdf
operating system ubuntu,linux,MacProgram will work only if you g.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
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
how to reuse code
how to reuse codehow to reuse code
how to reuse code
 
Introduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdfIntroduction You implemented a Deck class in Activity 2. This cla.pdf
Introduction You implemented a Deck class in Activity 2. This cla.pdf
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
 
How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Chp4(ref dynamic)
Chp4(ref dynamic)Chp4(ref dynamic)
Chp4(ref dynamic)
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdfoperating system Linux,ubuntu,Mac#include stdio.h #include .pdf
operating system Linux,ubuntu,Mac#include stdio.h #include .pdf
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
 
Let’s talk about microbenchmarking
Let’s talk about microbenchmarkingLet’s talk about microbenchmarking
Let’s talk about microbenchmarking
 
c programming
c programmingc programming
c programming
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyond
 

More from ajoy21

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxajoy21
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxajoy21
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxajoy21
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxajoy21
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxajoy21
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxajoy21
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxajoy21
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxajoy21
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxajoy21
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxajoy21
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxajoy21
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxajoy21
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxajoy21
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxajoy21
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxajoy21
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxajoy21
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxajoy21
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxajoy21
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxajoy21
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxajoy21
 

More from ajoy21 (20)

Please complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docxPlease complete the assignment listed below.Define and explain, us.docx
Please complete the assignment listed below.Define and explain, us.docx
 
Please cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docxPlease cite sources for each question. Do not use the same sources f.docx
Please cite sources for each question. Do not use the same sources f.docx
 
Please choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docxPlease choose one of the following questions to answer for this week.docx
Please choose one of the following questions to answer for this week.docx
 
Please check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docxPlease check the attachment for my paper.Please add citations to a.docx
Please check the attachment for my paper.Please add citations to a.docx
 
Please answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docxPlease answer to this discussion post. No less than 150 words. Refer.docx
Please answer to this discussion post. No less than 150 words. Refer.docx
 
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docxPlease attach Non-nursing theorist summaries.JigsawExecutive .docx
Please attach Non-nursing theorist summaries.JigsawExecutive .docx
 
Please answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docxPlease answer the question .There is no work count. PLEASE NUMBER .docx
Please answer the question .There is no work count. PLEASE NUMBER .docx
 
Please answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docxPlease answer the following questions. Please cite your references..docx
Please answer the following questions. Please cite your references..docx
 
Please answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docxPlease answer the following questions.1.      1.  Are you or.docx
Please answer the following questions.1.      1.  Are you or.docx
 
Please answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docxPlease answer the following question with 200-300 words.Q. Discu.docx
Please answer the following question with 200-300 words.Q. Discu.docx
 
Please answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docxPlease answer the following question Why do you think the US ha.docx
Please answer the following question Why do you think the US ha.docx
 
Please answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docxPlease answer the following questions. Define tunneling in the V.docx
Please answer the following questions. Define tunneling in the V.docx
 
Please answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docxPlease answer the following questions1. How can you stimulate the.docx
Please answer the following questions1. How can you stimulate the.docx
 
Please answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docxPlease answer the following questions very deeply and presicely .docx
Please answer the following questions very deeply and presicely .docx
 
Please answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docxPlease answer the following questions in an informal 1 ½ - 2-page es.docx
Please answer the following questions in an informal 1 ½ - 2-page es.docx
 
Please answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docxPlease answer the following questions in a response of 150 to 200 wo.docx
Please answer the following questions in a response of 150 to 200 wo.docx
 
Please answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docxPlease answer these questions regarding the (TILA) Truth in Lending .docx
Please answer these questions regarding the (TILA) Truth in Lending .docx
 
Please answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docxPlease answer the following question pertaining to psychology. Inc.docx
Please answer the following question pertaining to psychology. Inc.docx
 
Please answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docxPlease answer the following questions in a response of 250 to 300 .docx
Please answer the following questions in a response of 250 to 300 .docx
 
Please answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docxPlease answer the three questions completly. I have attached the que.docx
Please answer the three questions completly. I have attached the que.docx
 

Recently uploaded

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 

Recently uploaded (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 

#include stdafx.h using namespace std; #include stdlib.h.docx

  • 1. #include "stdafx.h" using namespace std; #include <stdlib.h> #include <math.h> #include <fstream> void quicksort(int [], int , int, int& ); void swap(int &, int &); int insertionSort(int [], int, int); // *** FOR ONLINE DATA STRUCTURES COURSE **** 11/19/11 // ******* STUDENTS -- GO TO THE mymain FUNCTION AND READ THE COMMENTS. DO NOT MODIFY ANY CODE OTHER THAN THE TWO FUNCTIONS YOU HAVE TO WRITE ******* int insertion_style_sort(int data[], int len, int a[], int limit) { // general insertion sort which uses increments you supply // can be used to perform Sedgewick, Hibbard, 531 and Shell sorts (or with any increments) // data[] this is the data to sort // len number of elements in data to sort // a[] increments to use for sorting (highest first, last increment is always 1). // limit number of increments int counter=0, gap, i, j, temp; for(int k = limit; k >= 0; k--) { gap = a[k]; for( i = gap; i < len; i++) { temp = data[i]; counter++; for( j = i; j >=gap && temp < data[j - gap]; j-=gap)
  • 2. { data[j] = data[ j - gap]; counter++; } data[j] = temp; } if(gap == 1)break; } return counter; // return the number of operations performed } int insertionSort(int data[], int start, int stop) { int count; int a[2]; a[0] = 1;// create the increments (which are just 1) a[1] = 1; count = insertion_style_sort(data, stop - start, a, 1); return count; } int shellsort_Shellincrements(int data[], int len) {// this code is taken from the Weiss text int j=0, limit, temp, counter=0; int *a = new int[len/2]; limit = j = log10((double)len)/log10(2.); // create Shell's increments for(int gap = len/2; gap > 0; gap /= 2) { a[j--] = gap; } counter = insertion_style_sort(data, len, a, limit); return counter; } int shellsort_531increments(int data[], int len) {// this code is taken from the Weiss text and demonstrates the
  • 3. example on p 257 using this set of increments int a[]={1, 1, 3, 5}; // this was wrong in the code on the Bb int counter = insertion_style_sort(data, len, a, 3); return counter; } int shellsort_Hibbardsincrements(int data[], int len) {// this code is taken from the Weiss text and demonstrates the example on p 257 using this set of increments int *a; double x = len; x = log10(x)/log10(2.); int ix = (int)x; // create the increments for Hibbard a = new int[ix+1]; for(int k = ix; k >= 1; k--) a[k] = (int)pow(2., (double)k) - 1; a[0]= 1; int counter = insertion_style_sort(data, len, a, ix); delete [] a; return counter; } int shellsort_Sedgewicksincrements(int data[], int len) {// this code is taken from the Weiss text and demonstrates the example on p 257 using this set of increments // I added the code to create the increments int i, j, temp, gap, counter=1;// don't return zero double x, y; i = 0; //Compute the increment sequence for this size sample (len) while(true) // solve for i, 9 * 4^i - 9 * 2^i + 1 = len { if( (j=(9*(int)pow(4., i) - 9*(int)pow(2., i) + 1)) > len)break; i++; }
  • 4. x = i; i = 0; while( true) // solve for i, 4^i - 3 * 2^i + 1 = len { if( (j=((int)pow(4., i) - 3*(int)pow(2., i) + 1)) > len)break; i++; } y = i; if(y > x)x = y; // take the larger of the two int ix = (int)x; int *a = new int[2*ix+2];// create an array to hold the increments for(i = 0; i < ix; i++) { // create the increments a[2*i] = (int)(9*(pow(4., (double)i) - pow(2., (double)i)) + 1); a[2*i+1] = (int)(pow(4., (double)i) - 3.*pow(2., (double)i) + 1); if(a[2*i+1] < 1)a[2*i+1] = 1; } insertionSort(a, 0, 2*ix-1);// sort the increments in descending order int limit = 2*ix-1; // perform the insertion style sort on the data with these increments counter = insertion_style_sort(data, len, a, 2*ix-1); return counter; } // ***************** EXAMPLE FUNCTION - use this to see how to write the two functions below, but use your own increment strategy ***************************************************** ****** int shellsort_Rootsincrements(int data[], int len) { // made up by DJF to show how to create and test your own algorithm // for this strategy, use 5 increments consisting of the following roots of len, 1/2, 1/3, 1/4, 1/5
  • 5. int *a; int ix = 5; int j=2;// start at the square root (it is the largest increment) a = new int[ix+1]; a[0] = 1; // last increment must always be 1 else you won't get a complete sort // increments must be in descending order (largest to smallest, with 1 being the last increment) for(int k = ix; k >= 1; k--) a[k] = (int)pow((double)len, (double)1/(double)(j++)); int counter = insertion_style_sort(data, len, a, ix); // leave this code in place delete [] a; return counter; } // ***************************************************** *********************** // ***************** YOUR FUNCTION - YOU WRITE THIS (this is a copy of the shellsort_Rootsincrements that you can modify ***************************************************** ****** int shellsort_yyyincrements(int data[], int len) { int *a; int ix = 5; int j=2;// start at the square root (it is the largest increment) a = new int[ix+1]; a[0] = 1; // last increment must always be 1 else you won't get a complete sort // increments must be in descending order (largest to smallest, with 1 being the last increment (stored at location a[0] ) for(int k = ix; k >= 1; k--)
  • 6. a[k] = (int)pow((double)len, (double)1/(double)(j++)); int counter = insertion_style_sort(data, len, a, ix); // leave this code in place delete [] a; return counter; } // ***************************************************** *********************** // ***************** YOUR FUNCTION - YOU WRITE THIS (this is a copy of the shellsort_Rootsincrements that you can modify ***************************************************** ****** int shellsort_zzzincrements(int data[], int len) { int *a; int ix = 5; int j=2;// start at the square root (it is the largest increment) a = new int[ix+1]; a[0] = 1; // last increment must always be 1 else you won't get a complete sort // increments must be in descending order (largest to smallest, with 1 being the last increment (stored at location a[0] ) for(int k = ix; k >= 1; k--) a[k] = (int)pow((double)len, (double)1/(double)(j++)); int counter = insertion_style_sort(data, len, a, ix); delete [] a; return counter; } // *****************************************************
  • 7. *********************** void mycopy(int source[], int dest[], int n) { for(int i=0; i < n; i++)dest[i] = source[i]; } void gendata(int array[], int length, int modulus, int base) { for(int i=0; i < length; i++) array[i] = rand()%modulus + base; } int mymain() // don't modify this code { // ***************************************************** ********* // file format for exporting graphs to DSWB //Number of curves (int) (blank) Number of points in a curve (must be 15) //Graph Title (char string) //Curve Labels (char string with | delimiter) //X axis label (char string) //Y axis label (char string) // Showcurves (char string) // Scalecurves (char string) // Graph style (char string -> loglog, loglinear, linearlog, linearlinear) // X points (one line, 15 points) // Y points for curve #1 (one line, 15 points) // Y points for curve #2 // Y points for curve #3 //.... //.... // Y points for curve 11 // ***************************************************** ***********
  • 8. int *data, *save; // arrays to hold data to be sorted, and also to back it up int counts [10] [15]; // results of sorts (counts) saved for graphing ofstream fpout; // file stream for data file to be read by sdiapp.exe // ofstream fpout1; // file stream for sorted output to be used while debugging the code fpout.open("edit1.txt");// name this file so sdiapp.exe will open without you having to type name if(fpout.fail()) // did the file open? { cout << "Data file (data) did not open"; system("pause"); exit(0); } // uncomment this code if you want to write output sorted data //fpout1.open("output.txt"); //if(fpout1.fail()) //{ // cout << "Data file (output) did not open"; // system("pause"); // exit(0); //} int nc = 8; // This is the number of curves including your 3. int np = 15; // This stays at 15 to be compatible with the DSWB fpout << nc << " " << np << endl; // number of curves (nc) and number of points/curve (np) fpout << "Sort Increments" << endl; // graph title fpout << "Shell|Hibbard|Sedgewick|Roots|My2|My3|531|Increment| " << endl; // curve labels fpout << "Sample Size(N)" << endl; // Horizontal axis title fpout << "Operations" << endl; // Vertical axis title fpout << "01234567890" << endl;// you don't need to change this
  • 9. fpout << "01234567890" << endl;// you don't need to change this fpout << "loglog" << endl; // can be loglog, loglinear, linearlog, linearlinear (upper of lower case) int samples[15] = {8, 16, 32, 48, 64, 96, 128, 256, 512, 1024, 2048, 3072, 4096, 8192, 16384}; for(int i = 0; i < 10; i++) // set the counts arrays to 1 (because your routines are not written yet) for(int j=0; j < 15; j++) counts[i][j] = 1; // use 1 instead of zero because log plots won't work with a zero // generate 15 data points for each curve int N; for(int i = 0; i < 15; i++) { N = samples[i]; // get the sample size data = new int[N]; // allocate storage save = new int[N]; gendata(data, N, RAND_MAX, 0); // generate the data mycopy(data, save, N); // save the dat for restore, else you will be sorting data already sorted counts[0][i] = shellsort_Shellincrements(data, N);// call each routine and capture it's count mycopy(save, data, N);// restore to the unsorted state for the next routine counts[1][i] = shellsort_Hibbardsincrements(data, N); mycopy(save, data, N); counts[2][i] = shellsort_Sedgewicksincrements(data, N); mycopy(save, data, N); counts[3][i] = shellsort_Rootsincrements(data, N); // here is an an example, I an using the roots of N mycopy(save, data, N); counts[4][i] = shellsort_yyyincrements(data, N); mycopy(save, data, N); counts[5][i] = shellsort_zzzincrements(data, N); mycopy(save, data, N);
  • 10. // other reference curves - counts[6][i] = shellsort_531increments(da ta, N); mycopy(save, data, N); counts[7][i] = insertionSort(data, 0, N-1); mycopy(save, data, N); delete [] data; } for(int i = 0; i < 15; i++) { // write independent data on the first line fpout << samples[i] << " "; } fpout << endl; for(int i=0; i < nc; i++) { for(int k = 0; k < 15; k++) { fpout << counts[i][k] << " "; } fpout << endl; } fpout.close(); // fpout1.close(); // uncomment if you use fpout1 return 0; } Solution #include<stdio.h> #include<conio.h>
  • 11. int main() { int arr[30]; int i,j,k,tmp,num; printf("Enter total no. of elements : "); scanf("%d", &num); for(k=0; k<num; k++) { printf(" Enter %d number : ",k+1); scanf("%d",&arr[k]); } for(i=num/2; i>0; i=i/2) { for(j=i; j<num; j++) { for(k=j-i; k>=0; k=k-i) { if(arr[k+i]>=arr[k]) break; else { tmp=arr[k]; arr[k]=arr[k+i]; arr[k+i]=tmp; }
  • 12. } } } printf("t**** Shell Sorting **** "); for(k=0; k<num; k++) printf("%dt",arr[k]); getch(); return 0; }