C program !!!Help!!!

superlative56

Co @dmin
Jan 18, 2007
2,896
9
43
SuperSite Area-56
This is a part of my Data structures semester project Bubble sorting Demo. My project is almost complete but only hav one problem in this part i hav to show sorting in Passes like compare 1>2, 2>3 ..... in first pass larger number sorted out and so on.... Currently my program generate 10 un sorted random numbers and directly sort them using bubble sort. can any one help me out showing sorting step by step... Im also working on it . My laziness dont hav much time .

Code is attached in a txt file...

waiting for your response guys.
 
Last edited:

Rapchik Killer

Well-known member
Jan 18, 2007
1,263
0
41
34
Karachi, Pakistan
I dont have c so i am cant try the code out... neway i think u just gotta change the bubble_sort code to this:

Code:
void bubble_sort( int a[], int n )  // Define Array and size of array
{
    int i, j;

    for (i = 0; i < n; i++)        // Make a pass through the array for each element
    {
        for (j = 1; j < (n-i); j++) // Array traversal (from beginning to end)
        {
            if (a[j-1] > a[j])      // If 1st number is greater then 2nd swap it!
            {
                SWAP(a[j-1],a[j]);
                 printf("%i > %i ", a[j-1], a[j])
            }
        }
    }
}
 

Desolator

King
Jan 21, 2007
6,901
12
44
40
Rawalpindi, Pakistan
Try this code. Hope it helps.

#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define COUNT 10
void main(void)
{
int i, j, temp; //Variables
int Array[COUNT]={9,8,7,6,5,4,3,2,1,0}; //Array List

/*
* (Count -1) is used as the last loop is not required.This is because
* when we reach the last number we know it is the maximum integer.
* Therefore, we can skip the last iteration.
*/
for(i=0;i< COUNT-1; i++)
{
/*The last iteration is ignored to avoid access out of range of the array.
E.g when we reach 9 the term Array[9]>Array[10] will produce an error.
*/
for(j=0;j< COUNT-1; j++)
{
if(Array[j]>Array[j+1]) // Swaping operation
{
temp=Array[j];
Array[j]=Array[j+1];
Array[j+1]=temp;
}
printf("%d ",Array[j]); //Printing integer
}
printf("%d\n",Array[j]); //Printing the bubbled out integer(the last integer) and going to the next line
}
getch();
}
 

superlative56

Co @dmin
Jan 18, 2007
2,896
9
43
SuperSite Area-56
thanks for response... Rapchick Killer and desolator

My mistake i didnt mention i hav to show sorting Graphically ....

something to do with n[max] and *str but wat ???
 
General chit-chat
Help Users
We have disabled traderscore and are working on a fix. There was a bug with the plugin | Click for Discord
  • No one is chatting at the moment.
    C cattoboee: yo