Posted by MindBreaker at 2:14 PM
Read our previous post
Write a
program which passes the address of an integer array to a pointer
variable declared in a function bubble sort that with the help of that pointer
variable and show result main()
variable declared in a function bubble sort that with the help of that pointer
variable and show result main()
Source code
#include
<iostream>
using namespace std;
void
bubble(int*,int);//////////////////prototype
void
main()
{
int
Array[5],size=5,*pointer;
for(int num=0;num<size;num++)
{
cout<<"Enter
element no : "<<num+1<<endl;
cin>>Array[num];
}
pointer=Array;
bubble(pointer,size);
}
void
bubble(int *pointer,int
size)
{
for(count1=0;count1<size-1;count1++)
{
for(count2=0;count2<size-count1-1;count2++)
{
if(*(pointer+count2)>*(pointer+count2+1))
{
swap=*(pointer+count2);
*(pointer+count2)=*(pointer+count2+1);
*(pointer+count2+1)=swap;
}
}
}
for(count1=0;count1<size;count1++)
{
cout<<*(pointer+count1)<<" , ";
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.