Searching and Sorting

Why does this not compile?

Page 1 of 1

2 Replies - 736 Views - Last Post: 07 May 2010 - 07:57 PM Rate Topic: -----

#1 Guest_APL*


Reputation:

Searching and Sorting

Posted 07 May 2010 - 06:57 PM

DIRECTIONS ARE ATTACHED
/* assignment3: */

int main(void) //users choice
{
	int choice = 0; /*users choice*/

        /*offer user choice of options*/
        printf("Please enter a number from 1 through 6. Your choice will execute the following with a predetermined array;\nChoose an option;\n");
        printf("1.  Sequential Search\n");
        printf("2.  Binary Search\n");
        printf("3.  Bubble Sort\n");
        printf("4.  Selection Sort\n");
        printf("5.  Insertion Sort\n");
        printf("6.  End Program\n");

	while (userChoice != 6) { /*while user does not want the program to end*/

		int numberArray[SIZE] = {17, 2, 35, 29, 99, 12, 67, 54, 45, 1}; /*set up array to default every time array is accessed by user*/

		printf("\n\n\nEnter a value from 1 through 6:"); /*prompt user*/
        scanf("%d", &choice);
    
		switch(choice) { /*search for users choice*/

            case 1: /*execute sequential search*/
                sequentialSearch(numberArray, SIZE);
                break;
            case 2: /*execute binary search*/
                insertionSort(numberArray, SIZE);
                binarySearch(numberArray, SIZE);
                resetArray(numberArray); 
                break;
            case 3: /*execute bubble sort that is not organizational purposes only*/
                printf("Unsorted array:\n");
                displayArray(numberArray, SIZE); 
                bubbleSort(numberArray, SIZE); 
                printf("Sorted array:\n");
                displayArray(numberArray, SIZE); 
                resetArray(numberArray); 
                break;
            case 4: /*execute selection sort*/
                printf("Unsorted array:\n");
                displayArray(numberArray, SIZE); 
                selectionSort(numberArray, SIZE); 
                printf("Sorted array:\n");
                displayArray(numberArray, SIZE); 
                resetArray(numberArray); 
                break;
            case 5: /*execute insertion sort*/
                printf("Unsorted array:\n");
                displayArray(numberArray, SIZE);
                insertionSort(numberArray, SIZE); 
                printf("Sorted array:\n");
                displayArray(numberArray, SIZE);
                resetArray(numberArray); 
                break;
            case 6: /* lets userknow that the program is ending*/
                printf("Program has ended.\n");
                break;

            default: /* lets user know they put in incorrect input*/
                printf("Incorrect input.  Please enter a number 1 through 6 only.\n");
                break;

        } /*end switch*/
               
    } /*end while*/
    
    return 0;    /*indicates successful termination*/
    
} /*end main program*/


Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0

Replies To: Searching and Sorting

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Searching and Sorting

Posted 07 May 2010 - 07:52 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:


  • Post the code you're having problems with (DONE)
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,273
  • Joined: 27-December 08

Re: Searching and Sorting

Posted 07 May 2010 - 07:57 PM

I would guess that your code isn't compiling b/c you haven't defined the functions for your sorting, searching, or display routines.

In case you are not comfortable implementing the sorting or binary search algorithms, I've included links you may find helpful:
http://en.wikipedia..../Insertion_sort
http://en.wikipedia..../Selection_sort
http://en.wikipedia....wiki/Bubblesort
http://en.wikipedia....i/Binary_Search
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1