Using C++ How can I alter the code so it will print the array of names in alphabetical order?
473239
Several problems:\n\n>  bubble_sort(names[3]);\n\nthis is accessing the 4th element of the names array (first 3 elements are at indices 0, 1, and 2). this is why you're getting your output, it's not sorting anything! i'm surprised this program didn't crash. instead you simply want to pass 'names' as the parameter - this means you are passing the entire array as a parameter, not a single element of the array. proper:\n   bubble_sort(names);\n\n>           if (array[j+1] > array[j])\n\nthis would sort the array opposite the way you want it. simple fix is using less-than instead of greater-than. BUT, if i'm not mistaken, you can't compare strings like that. you have to use strcmp, like this:\n            if (strcmp(array[j+1], array[j]) < 0)\notherwise, you are just comparing pointers.
979933
I'm giving u the program (in C), just go through it, then write the algo. It'll be easier.\n\n// Program :  MERGE  SORT\n\n#include<stdio.h>\n#include<conio.h>\n\nvoid mergesort(int *,int);\n\nvoid main()\n{\nint x[30],n,i;\nclrscr();\nprintf("Enter total no. of elements");\nscanf("%d",&n);\nprintf("Enter %d nos.",n);\nfor(i=0;i<n;i++)\n   scanf("%d",&x[i]);\n\nmergesort(x,n);\n\nprintf("After sorting in descending order :&#92;n");\nfor(i=n-1;i>=0;i--)\n  printf(" %d",x[i]);\n\ngetch();\n}\n\n\n\nvoid mergesort(int x[],int n)\n{\n  int aux[30],l1,l2,u1,u2,i,j,k,size;\n  size=1;   // merges file of size 1\n  while(size<n)\n  {\n    l1=0;   // initialize lower-bound of 1st. file\n    k=0;    // k is index for auxilliary array\n    while(l1+size<n)\n    {\n      // initialize remaining parameters...\n      l2=l1+size;\n      u1=l2-1;\n      u2=(l2+size-1)<n ? (l2+size-1):(n-1);\n      for(i=l1,j=l2;i<=u1 && j<=u2;k++)\n if(x[i]<=x[j])\n   aux[k]=x[i++];\n else\n   aux[k]=x[j++];\n      while(i<=u1)\n      aux[k++]=x[i++];\n      while(j<=u2)\n      aux[k++]=x[j++];\n\n      l1=u2+1;\n    } /* end of 2nd. while-loop */\n    for(i=l1;k<n;i++)\n       aux[k++]=x[i];\n    for(i=0;i<n;i++)\n       x[i]=aux[i];\n\n    size*=2;\n  } /* end of 1st. while-loop */\n}
291972
They're arranged in alphabetical order
1078538
it is called a palindrome.\n\nBob\nMom\nDad\nRacecar\nKayak\nPop\nPep\nPeep\n\nthe list goes on!
698365
What you are trying to do is actually part of a larger sorting algorithm called "Merge Sort".\n\nhere is an example:\nhttp://mathbits.com/MathBits/CompSci/Arrays/Merge.htm\n\nYou would keep merging the sorted arrays in set K into the "master" sorted array.  Thus, you would only be working with two sorted arrays at any one time.\n\nSearch the net for "Merge Sort" for other implementations.
926631
use the function 'toCharArray()'\n\nexample:\nString name = "mary";\nchar[]nameByte = name.toCharArray();
112082
I'm not a techno geek but I assume it means that it prints sorted alphabetically, numerically, or in some order other than the order of data entry.
434435
It may be easier to use an array list.\n\n  Dim al As New ArrayList()\n\n   al.Add("This")\n   al.Add("Is")\n   al.Add("My")\n   al.Add("New")\n   al.Add("ArrayList")\n   al.Add("Control")\n\n   Console.WriteLine("Before Sort:")\n   WriteElements(al)\n\n   al.Sort()\n\n   Console.WriteLine("After Sort:")\n   WriteElements(al)\n End Sub\n\n Private Sub WriteElements(ByVal al As ArrayList)\n   Dim i As Integer\n   \n   For i = 0 To al.Count - 1\n     Console.WriteLine(CStr(al.Item(i)))\n   Next
419823
You may have to be more specific.\n\nalgorithm.h is not a standard library, as such it will be impossible to know what kind of code is in it.\n\nThere are numerous sorting algorithms, some more efficient than others.  There's bubble-sort, insertion-sort, heap-sort, quick-sort, etc.  If you're interested in searching and sorting, try doing a google search.\n\nThere is a sort() tool for UNIX systems, but that uses data streams and pipes at the console level, not intended for use inside a program.\n\nIf you want, you can open up algorithm.h and take a look inside.  You won't be able to see what the function definitions are, but at least you can see what parameters it takes.  Also, if you're really lucky ;-) there will be comments in the file describing what kind of sort it uses.  Just do a little detective work, and you can get all the info you need.
646616
class publication\n{\n   private :\n      char title[20];\n      float price;\n   public :\n      void getdata()\n      {\n          cin>>title;\n          cin>>price;\n      }\n};\nclass books :: public publication\n{\n   private :\n      int pagecount;\n   public :\n      void getdata()\n      {\n          cin>>pagecount;\n      }\n\n};\nclass tape :: public publication\n{\n   private :\n      int playing_time;\n   public :\n      void getdata()\n      {\n          cin>>playing_time;\n      }\n};
860428
u gotta use somesort of code
604118
This is an identical java code for your C++ code,\n\n1. create a filename, say HelloWorld.java,\n\n2. Write in following codes,\n\npublic class HelloWorld\n{\n      public static void main (String args[])\n      {\n           System.out.println("Hello World");\n      }\n}\n\n3. Save it and compile it. Then open the class file using java.
1059802
well that is an easy one.....\n\nIt is in alphabetical order
1110691
Here is something I came up with quickly ( not fully complete, I will leave that to you ! ) \n\nThis quick bit of code will give you a start ( hopefully and no recursion ).\n\nPlease note that this is not complete and you will get a memory leak in swap function ( easily fixed btw ! ).\n\n#include "stdafx.h"\n#include "stdio.h"\n#include "string.h"\n\nvoid manipulate( char* pString, int index );\nchar* swap( char* pString, int pos );\n\nchar pod[255];\n\n\nint main(int argc, char* argv[])\n{\n\n  char* p = "abc";\n  memcpy( pod, p, strlen( p ) );\n  for( int i = 0; i < strlen( p ); i ++ )\n  {\n    manipulate( pod, strlen( p ) );\n  }\n  return 0;\n}\n\n\nvoid manipulate( char* pString, int index )\n{\n  int i = 1;\n  char* p;\n  p = pString;   \n  while( index > 1 ) \n  {\n    p = swap( p, i );\n    index--;\n    i++;\n    memcpy( pod, p, strlen( pString ) );\n    printf( "%s&#92;n", p );\n  }\n}\n\nchar* swap( char* pString, int pos )\n{\n  char* p = new char[ strlen(pString) + 1 ];\n  memset( p, '&#92;0', strlen( pString ) + 1);\n  memcpy( p, pString, strlen( pString ) + 1 );\n  char temp = p[pos];\n  p[pos] = pString[pos-1];\n  p[pos-1] = temp;\n  return p;\n}
447556
Look up "quicksort".\n\nIt fits very naturally into a recursive implementation\nand is also a very efficient sorting algorithm.\n\nI've included a link to the Solaris source for quicksort.\nIt is written in C (rather than C++).  It is somewhat\ncomplicated because it optimizes the sorting of\nshort sequences by switching to an insertion sort.\nHowever, you could implement a simpler version which\nran quicksort all the way to completion.
1178151
If you know max.allowed width, use \nprintf( "%*.*s", width, width, arr[idx] )\n\nvoid printArray( char ** strings, int arr_sz, int columns, int min_width )\n{\nint rows = arr_sz/columns;\nfor( row = 0; row < rows, row++ )\nfor( col = 0; col < columns; col++ )\n{\n     int idx = columns*row+col;\n     if( idx >= arr_sz )\n           break;\n     printf( "%*.*s&#92;t", min_width, min_width , arr[idx] );\n}\nprintf( "&#92;n" );\n}
1094860
By the sound of it, either you need a tutorial or you're asking about code formatting.   Try the tutorial at the first URL below.  For formatting stuff, you can search for "C  +code formatting" and get a few hits;-)  I hope this will get you started.   I've also included a link to lots of free resources such as compilers, editors, articles and other helpful sites.  Good luck!