buffering the bytes

Subscribe to RSS feed

Posts tagged with "notes"

Bubble Sort[modified version]

, , ,

Q.Given an unsorted integer array, place all zeros to the end of the array without changing the sequence of non-zero elements. (i.e. [1,3,0,8,12, 0, 4, 0,7] --> [1,3,8,12,4,7,0,0,0])
#include<iostream>
using namespace std;


int main()
{	
	int a[]={1,0,2,0,0,3,0,4,0};
	int count = 0;
	int temp;
	
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8-i;j++)
		{
			if(a[j] == 0)
			{
				while(a[j+1] !=0)
				{temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;j++;}	
			}
		}	
		
		
	}
	
	for(int i=0;i<8;i++)
	{
		cout << a[i];
		}
	
	return 0;
}
May 2013
M T W T F S S
April 2013June 2013
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