Sorting string values without using any method/function

how to sort string array in java without using sort method
how to sort list of strings in ascending order without using java api
sort an array without using inbuilt function in javascript
how to sort an array without using sort method c#
sort array of strings c++
sort array without using sort function
c# sort string array alphabetically
how to sort a list alphabetically in python without sort function

I trying to do sorting without use of any method or function

My Code :

   string[] names = { "Flag", "Nest", "Cup", "Burg", "Yatch", "Next" };                     
   string name = string.Empty;
   Console.WriteLine("Sorted Strings : ");

   for (int i = 0; i < names.Length; i++)
        {
            for (int j = i + 1; j < names.Length; j++)
            {
                for (int c = 0; c < names.Length; c++)
                {
                    if (names[i][c] > names[j][c])
                    {
                        name = names[i];
                        names[i] = names[j];
                        names[j] = name;
                    }
                }

            }
            Console.WriteLine(names[i]);
        }

Please let me bring any solution for this code ?

In this code i am getting "Index was outside the bounds of the array" exception

You need to implement a sorting algorithm.

A very simple algorithm you can implement is the insertion sort:

string[] names = { "Flag", "Nest", "Cup", "Burg", "Yatch", "Next" };

for (int i = 0; i < names.Length; i++)
{
    var x = names[i];
    var j = i;
    while(j > 0 && names[j-1].CompareTo(x) > 0)
    {
        names[j] = names[j-1];
        j = j-1;
    }
    names[j] = x;
}

Sort Array In C# Without Using Inbuilt Function, Example 1 - Sort an array in ascending order without using inbuilt C# function one integer array having values 2,9,4,3,5,1,7 in the array as described in static void Main(string[] args); {; int[] intArray = new int[] {2,9,4,3,5,1,7 }  The goal of this Code Golf is to create a program that sorts a list of strings (in ascending order), without using any built-in sort method (such as Array.Sort() in.NET, sort() in PHP,). Note that this restriction excludes using a built-in method that sorts an array descending, and then reversing the array.

        int temp = 0;
        int[] arr = new int[] { 20, 65, 98, 71, 64, 11, 2, 80, 5, 6, 100, 50, 13, 9, 80, 454 };
        for (int i = 0; i < arr.Length; i++)
        {
            for (int j = i + 1; j < arr.Length; j++)
            {
                if (arr[i] > arr[j])
                {
                    temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
            Console.WriteLine(arr[i]);
        }
        Console.ReadKey();

how to sort string without using array.sort, Here's a 'naive' approach to sorting strings which only works if (as here) the And here's another approach which uses the Gnome sort algorithm These letters have ASCII/Unicode values between 65 and 90 inclusive. String class doesn’t have any method that directly sort a string, but we can sort a string by applying other methods one after other. Method 1(natural sorting) : Apply toCharArray() method on input string to create a char array for input string. Use Arrays.sort(char c[]) method to sort char array.

string[] names = { "Flag", "Next", "Cup", "Burg", "Yatch", "Nest" };
        string name = string.Empty;
        Console.WriteLine("Sorted Strings : ");

        for (int i = 0; i < names.Length; i++)
        {
            int c = 0;
            for (int j = 1; j < names.Length; j++)
            {
                if (j > i)
                {
                 Sort:
                    if (names[i][c] != names[j][c])
                    {
                        if (names[i][c] > names[j][c])
                        {
                            name = names[i];
                            names[i] = names[j];
                            names[j] = name;
                        }
                    }
                    else
                    {
                        c = c + 1;
                        goto Sort;
                    }                        
                }
            }
            Console.WriteLine(names[i]);
        }

How to sort a string array alphabetically without using Arrays.sort , How do I shift all elements of an array with the input value in Java? 2,077 Views How do I sort a string alphabetically in Python without using the sort function? Java provides compareTo() method to compare the two string lexographically. How do we replace every element with the greatest element in an array? You can't. As I told you last time it's a logical contradiction to have some code that sorts something (which itself is therefore a sorting algorithm) and to also not use a sorting algorithm. It's like asking us how you can run a running race without moving your legs. You just don't seem to be learning what's wrong with your question.

I you were conflicting in length of names array and comparing string. Below is the working solution . I have tested it it's working now

static void Main(string[] args)
        {
            int min=0;

            string[] names = { "Flag", "Nest", "Cup", "Burg", "Yatch", "Next" };
            string name = string.Empty;
            Console.WriteLine("Sorted Strings : ");

            for (int i = 0; i < names.Length-1; i++)
            {
                for (int j = i + 1; j < names.Length;j++ )
                {

                    if(names[i].Length < names[j].Length)
                           min =names[i].Length;
                    else
                            min =names[j].Length;
                    for(int k=0; k<min;k++)
                    {
                        if (names[i][k] > names[j][k])
                        {
                            name = names[i].ToString();
                            names[i] = names[j];
                            names[j] = name;
                            break;
                        }
                        else if(names[i][k] == names[j][k])
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }

                    }
                }


            }
            for(int i= 0;i<names.Length;i++)
            {
                Console.WriteLine(names[i]);
                Console.ReadLine();
            }
        }
    }

Print array of strings in sorted order without copying one string into , Given an array of n strings. The task is to print the strings in sorted order. We can apply any sorting technique to this indexed_arr. An corresponding index array will be indexed_arr = {0, 1} --> Now, how the strings are compared and accordingly values in indexed_arr are changed. function to print strings in sorted order. How to sort elements without using built in functions ; Trying to set a Variable maximum and minimum value. JUnit Assert method ; Finding the standard deviation in python ; python - finding the maximum value ; is there a better way ; Java code to compare 3 numbes to check the minimum and maximum values ; Need an interface for python 2.6.3 and mysql-5.1.31

class Program
{
    static void Main(string[] args)
    {
        int[] arr = new int[] {9,1,6,3,7,2,4};
        int temp = 0;

        for (int i = 0; i < arr.Length; i++)
        {
            for (int j = i + 1; j < arr.Length;j++)
            {
                if(arr[i]>arr[j])
                {
                    temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }

            Console.Write(arr[i]+",");
        }
             Console.ReadLine();
    }

how to sort a list of numbers without using built-in functions like min , how to sort a list of numbers without using built-in functions like min, max order without using any inbuilt Sorting Methods and Functions. How can I write code to find a palindrome in python without using string functions? @Phantom007 Because you need to compare each element in the array against each position in itself, if you do it only once the result would be [4, 8, 5, 4, 2, 7, 6, 9, 10, 3, 1] or something similar because you are only ever comparing the first one to it's neighbor and not to all of them, if it's just number coparing you could probably do something funky with min/max and only 1 loop but that

C# Sharp Exercises: Sorts the strings of an array using bubble sort , C# Sharp Exercises: Sorts the strings of an array using bubble sort Write a program in C# Sharp to read a string through the keyboard and sort it to extract a substring from a given string without using the library function. Sort Integer array without using sort() method -Java Hi Viewers This post is regarding a small code snippet which helps us to sort an integer array of elements without using any of the sort() method present in Arrays or Collections in Java API.We used bubble sort technique to sort the integer array.This is being asked frequently in written exams of interviewing process.Hope this code snippet helps you

Sorting a list of strings without using any built-in sort method, GolfScript, 26 25 bytes. ","/.,{{.2$<{\}*}*]}*","*. Straightfoward implementation of Bubble Sort. Try it online in Web GolfScript. How it works. ","/ # Split the input string  The inner loop is a bubble sort, and the outer loop runs the bubble sort the absolute maximum number of times it’d take to sort the list using bubble sort (actually, once more than that). You’d usually stop when the list was sorted instead.

Array methods, The splice method is also able to insert the elements without any removals. It's similar to a string method str.slice , but instead of substrings it makes subarrays. forEach method allows to run a function for every element of the array. It also returns the sorted array, but the returned value is usually  Find lexicographically smallest string in at most one swaps; Sort an Array which contain 1 to N values in O(N) using Cycle Sort; Sort the strings based on the numbers of matchsticks required to represent them; Count of smaller elements on right side of each element in an Array using Merge sort; Count number of pairs with positive sum in an array

Comments
  • And why don't you want to use a method or function? It could be as easy as using a simple LINQ statement...
  • If you do not want to execute any piece of code (resulting in a call of a method or function) there is not much left available that can solve this.
  • What specifically are your problems with this code? You get better answers if you ask specific questions. See also stackoverflow.com/help/how-to-ask
  • You don't need three loops over that names array. Two is enough. Or should that c loop go over names[i].Length?
  • @ReinderWit i did with use of method & function... i am try without that.... so oly like this...
  • @siva What do you mean, without algorithms? You're asking for an algorithm!
  • i am not saying like that... am trying with swapping & looping
  • @siva That's exactly what this answer does
  • Is this question about helping OP by telling what he did wrong, or is it about dumping your favorite sort implementation?
  • ya here used string CompareTo method. my expected result is without any use of method is this possible to do sorting?
  • You should explain to him why you did what. Otherwise it is just a piece of code.
  • string[] names = { "Flag", "Fig", "Nest", "Cup", "Burg", "Yatch", "Next" };
  • convert the string char array. same way to done second char also. iterate the both characters. check the each character ASCII code and compere.