bubble sorting in linked list

This is a discussion on bubble sorting in linked list within the C Programming forums, part of the General Programming Boards category; hi everyone i was trying to sort a linked list using bubble sorting but i could not reach the end. ...

  1. #1
    anu
    anu is offline
    Registered User
    Join Date
    Oct 2001
    Posts
    9

    Question bubble sorting in linked list

    hi everyone


    i was trying to sort a linked list using bubble sorting but i could not reach the end. i need ur help to solve it. i dont know my logic is correct or not.

    here is a simple program of bubble sort with arrays.

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>

    void bubble(int x[]);

    int main() {
    int data[]={4,7,6,8,3};
    bubble(data);
    return 0;
    }

    void bubble(int x[])
    {
    int i, j, temp;
    for(i=0; i<=3; i++)
    {
    for(j=0;j<=3;j++)
    {
    if (x[j]>x[j+1])
    {
    temp=x[j];
    x[j]=x[j+1];
    x[j+1]=temp;
    }
    }
    }
    printf("after sorting.....\n");
    for(i=0;i<=4;i++)
    printf(" %d\n", x[ i ] ) ;
    }

    the attched file is the linked list program where i tried to use bubble sorting.
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Duplicating value of pointer to linked list
    By zephyrcat in forum C Programming
    Replies: 14
    Last Post: 01-22-2008, 03:19 PM
  2. sorting linked list
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 05-20-2006, 06:33 AM
  3. Sorting Linked List Problem
    By chriscolden in forum C Programming
    Replies: 8
    Last Post: 01-17-2006, 10:46 AM
  4. Linked list with two class types within template.
    By SilasP in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2002, 06:13 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21