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.
  • Necrokiller Necrokiller:
    MS: Hold my trillion dollars
    Link
  • Necrokiller Necrokiller:
    Sony: We can f**k up a totally good situation.
    Link
  • Link
  • XPremiuM XPremiuM:
    Started Dead Island 2, and i find it pretty lame. The story is shit. The characters are either cringe or bland (all 6 of them), The gameplay isn't fun. Even the goddamn zombies don't behave like proper zombies. They're all fast & intelligent unlike how zombies are supposed to be like. Any fan of "zombie" genre cannot possibly like this shitfest of a game. Dying Light 2 was million times better than this shit.
    Link
  • NaNoW NaNoW:
    so Baldurs Gate 3 is pretty great!"
    Link
  • faraany3k faraany3k:
    So who here is waiting for Senua Hellblade 2. Prequel was a true mind fuck experience.
    Link
  • GloriousChicken GloriousChicken:
    Sad indeed
    Link
  • NaNoW NaNoW:
    what a sad day
    Link
  • faraany3k faraany3k:
    Necrokiller said:
    MS one upping Sony in catching the biggest L in gaming
    tbh gaming industry as a whole is failing much like tech industry. They have buckled down too much to Corporate suites then relying on passionate and innovative people. A corporate only believes in financial growth and shareholders.
    Link
  • Necrokiller Necrokiller:
    MS one upping Sony in catching the biggest L in gaming
    Link
  • Link
  • NaNoW NaNoW:
    oh
    Link
  • StrikerX StrikerX:
    Still not available back on Steam though
    Link
  • C chamir44:
    My withdraw
    Link
  • Necrokiller Necrokiller:
    Reminds me of the time MS tried to charge PC gamers for online play
    Link
  • Necrokiller Necrokiller:
    When will console companies realize this sh*t doesn't work on PC
    Link
  • SolitarySoldier SolitarySoldier:
    doesn't change the fact that sony is extra chu this gen
    Link
  • Link
  • StrikerX StrikerX:
    Mofos sharpened a spear and shoved it up theirs and Arrowhead's ass
    Link
  • StrikerX StrikerX:
    Sony <3
    Link
  • Necrokiller Necrokiller:
    Jeez, throwing all those sales away for the sake of PsN accounts. What a mess.
    Link
  • Link
  • Chandoo Chandoo:
    faraany3k said:
    I have heard that it is now unplayable in countries which do not support handful of third world countries not recognized by Sony like Pakistan. Steam is a true global platform.Then they cry that console gaming is dying.
    170 + countries where Steam sells but PSN doesn't will lose access unless they use VPN
    Link
  • Chandoo Chandoo:
    It has a worst rating on Steam than last years MW3 now. Jeese Sony, how can you fuck it up THIS BAD
    Link
  • faraany3k faraany3k:
    I have heard that it is now unplayable in countries which do not support handful of third world countries not recognized by Sony like Pakistan. Steam is a true global platform.Then they cry that console gaming is dying.
    Link
    Necrokiller Necrokiller: MS: Hold my trillion dollars