Lexiographic series

Discussion in 'C' started by ASD, Aug 9, 2011.

  1. ASD

    ASD New Member

    Joined:
    Aug 9, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Sir.........
    I wanted your help in coding a lexiographic sorting.please do help me
     
  2. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    Is it sorting of strings???
     
  3. ASD

    ASD New Member

    Joined:
    Aug 9, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    yeah....
    it is the sorting of strings according to their alphabetic order.do you hav any logic for doing the same relating it with the bubble sort.if yes please do help me....:)
     
  4. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    include<stdio.h>
    int main()
    { 
     int i,j,n;  
    char str[20][20],temp[20];
      puts("Enter the no. of string to be sorted"); 
     scanf("%d",&n);
      for(i=0;i<=n;i++)      
    gets(str[i]);
      for(i=0;i<=n;i++)    
      for(j=i+1;j<=n;j++)
    {         
      if(strcmp(str[i],str[j])>0)
    {              
     strcpy(temp,str[i]);            
      strcpy(str[i],str[j]);            
      strcpy(str[j],temp);           
    }    
      } 
     printf("The sorted string\n");
      for(i=0;i<=n;i++)    
      puts(str[i]);  
    return 0;
    }
     
  5. ASD

    ASD New Member

    Joined:
    Aug 9, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    thank you so much .........
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice