Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

새싹교실/2017/내무반/한윤진/BubbleSort: Difference between revisions

From ZeroWiki
({CREATE})
 
imported>h94418
No edit summary
 
Line 1: Line 1:
#include <stdio.h>
#include &lt;stdio.h&gt;
 
void bubbleSort(int A[], int N);
void bubbleSort(int A[], int N);
 
int main()
int main()
{
{
int i;
int i;
int a&#91;5&#93;;
int a[5];
        for(int j=0;j<5;j++){         
        for(int j=0;j&lt;5;j++){         
                scanf("%d",&a&#91;j&#93;);
                scanf("%d",&amp;a[j]);
        }
        }
bubbleSort(a,5);
bubbleSort(a,5);
for (i=0;i<5;i++)  
for (i=0;i&lt;5;i++)  
printf(“%d\n”,a&#91;i&#93;);
printf(“%d\n”,a[i]);
 
return 0;
return 0;
}
}
void bubbleSort(int A[], int N)
void bubbleSort(int A[], int N)
{
{
int temp,i, j;
int temp,i, j;
for (i=N-1;i>=1;i--)  
for (i=N-1;i&gt;=1;i--)  
for (j=1;j<=i;j++)  
for (j=1;j&lt;=i;j++)  
if (A&#91;j-1&#93;>A&#91;j&#93;) {
if (A[j-1]&gt;A[j]) {
temp=A&#91;j-1&#93;;
temp=A[j-1];
A&#91;j-1&#93;=A&#91;j&#93;;
A[j-1]=A[j];
A&#91;j&#93;=temp;
A[j]=temp;
}
}
}
}



Latest revision as of 14:52, 18 May 2017

#include <stdio.h>

void bubbleSort(int A[], int N);

int main()
{
	int i;
	int a[5];
        for(int j=0;j<5;j++){        
                scanf("%d",&a[j]);
        }
	bubbleSort(a,5);
	for (i=0;i<5;i++) 
		printf(“%d\n”,a[i]);

	return 0;
}
void bubbleSort(int A[], int N)
{
	int temp,i, j;
	for (i=N-1;i>=1;i--) 
		for (j=1;j<=i;j++) 
			if (A[j-1]>A[j]) {
				temp=A[j-1];
				A[j-1]=A[j];
				A[j]=temp;
			}	
}