Jump to content

Search the Community

Showing results for tags 'example'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Calendars

There are no results to display.

There are no results to display.

Forums

  • General Discussion
    • Community Announcements
    • Evernote General Discussions
    • Evernote Integrations
    • Evernote Betas
    • Evernote API Discussion
  • FAQ's: Best Answers
    • FAQ's: Best Answers
  • Possible Bugs/Technical Issues
    • General Technical Issues
    • Evernote Business
    • Evernote for Android
    • Evernote for iOS
    • Evernote for Mac
    • Evernote for Windows
    • Web Client
    • Evernote Product Suite
  • Product Feedback/Feature Requests
    • General Feature Requests
    • Evernote Business
    • Evernote for Android
    • Evernote for iOS
    • Evernote for Mac
    • Evernote for Windows
    • Evernote Web Client
    • Evernote Product Suite
  • Evernote Forum Archives
    • Using Evernote
    • General Discussion Archive
    • Product Archives
  • Web Clipper***
  • International Forums
    • Japanese Discussions
    • Brazilian Portuguese Discussions
    • Discussions in Spanish
    • Korean Discussions
    • Traditional Chinese Discussions

Blogs

There are no results to display.

There are no results to display.

Categories

There are no results to display.

There are no results to display.


Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Subscription

Found 1 result

  1. Hi! I create this topic just for C# example of sorting and search algorithms. For your information I'm just a student. I'm from Sweden, so I write in swedish in WriteLine. I hope that you enjoy! static void Main(string[] args) { while (true) { //Creates an Array with value 100 int[] myArray = new int[100]; //Creates randomizer to make random numbers Random randomizer = new Random(); for (int i = 0; i < myArray.Length; i++) { myArray = randomizer.Next(1000); } //May choose among various sorting algorithms for sorting number (for example Bubble sort) SelectionSort(myArray); //Makes it "fancier" Console.Write("{ "); for (int i = 0; i < myArray.Length; i++) { Console.Write(myArray); if (i < myArray.Length - 1) { Console.Write(", "); } } Console.Write(" }\n"); Console.Write("Mata in talet som du vill hitta: "); int searchNumber = int.Parse(Console.ReadLine()); //Choose between Linear and Binary search: int pos = LinearSearch(searchNumber, myArray); if (pos == -1) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Talet finns inte.\nTryck 'ENTER' för att försöka igen."); } else { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Talet finns på position: "+ pos); } Console.ReadLine(); } } //Here is four methods for example (two sorting and two search algorithms) private static void SelectionSort(int[] myArray) { //Going through all non-sorted elements and find the smallest for (int i = 0; i < myArray.Length; i++) { //Assume that the first unsorted position contains the smallest value int minPos = i; for (int j = i; j < i; j++) { //If we find a smaller element, update minPos if (myArray[j] < myArray[minPos]) { minPos = j; } } //byt plats int tmp = myArray; myArray = myArray[minPos]; myArray[minPos] = tmp; } } private static void BubbleSort(int[] myArray) { for (int i = myArray.Length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (myArray[j] > myArray[j + 1]) { int tmp = myArray[j]; myArray[j] = myArray[j + 1]; myArray[j + 1] = tmp; } } } } private static int BinarySearch(int searchNumber, int[] myArray) { int min = 0; int max = myArray.Length - 1; while (min < max) { int mid = (min + max) / 2; if (searchNumber == myArray[mid]) { return mid; } else if (searchNumber < myArray[mid]) { max = mid - 1; } else { min = mid + 1; } } return -1; } private static int LinearSearch(int searchNumber, int[] searchArray) { int position = -1; for (int i = 0; i < searchArray.Length; i++) { if (searchNumber == searchArray) { position = i; break; } } return position; }
×
×
  • Create New...