Go4Expert (http://www.go4expert.com/)
-   Meet and Greet (http://www.go4expert.com/community/meet-and-greet/)
-   -   Bubble sorting (http://www.go4expert.com/community/bubble-sorting-t26971/)

 RajeshGalla 19Oct2011 23:34

Bubble sorting

I have to take the number of integers and the integers to be sorted, as input through console during execution of program and the integers will be saved into a pointerd.Then i will give the pointer as an arguement for the function that will bubble sort those integers.I am getting problem in function "bubbleSorting(int n,int *p)".Please someone help me
Code:

```#include<stdio.h> void main(void) {         int n,i;                      //n will be the number of integers that will be entered         printf("No of values:");         scanf("%d",&n);         int *p;         p=(int *)malloc (n * sizeof(int));/*dynamic memory allocation for saving the entered values*/         for(i=0;i<n;i++)         {                 scanf("%d",&p[i]);         }/*saving values in pointer*/         bubbleSorting(n,*p); } bubbleSorting(int n,int *p) {         int i,j;         printf("values before bubble Sorting:\n")         for(i=0;i<n;i++)         {                 printf("%d",p[i]);         }         for(i=0;i<n;i++)         {                 for(j=0;j<n;j++)                 {                         if(p[j]>p[j+1])                         {                                 p[j]=p[j]+p[j+1];                                 p[j+1]=p[j]-p[j+1];                                 p[j]=p[j]-p[j+1];                         }                 }         }         printf("values after Bubble sorting:\n");         for(i=0;i<n;i++)         {                 printf("%d\n",p[j]);         } }```

 All times are GMT +5.5. The time now is 07:06.