Like Tree1Likes
  • 1 Post By iMalc

error in Insertion_Sort

This is a discussion on error in Insertion_Sort within the C++ Programming forums, part of the General Programming Boards category; Code: #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int findSmallestRemainingElement (int array[], int size, int index); void swap ...

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    2

    error in Insertion_Sort

    Code:
    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    using namespace std;
    int findSmallestRemainingElement (int array[], int size, int index);
    void swap (int array[], int first_index, int second_index);
    void sort (int array[], int size)
    {
    for ( int i = 0; i < size; i++ )
    {
    int index = findSmallestRemainingElement( array, size, i );
    swap( array, i, index );
    }
    error msg:undefined reference to'findSmallestRemaingElement(int*,int,int)'.
    No other error inthis program.Where is the error?.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    You need to implement that function.

    Code:
    int findSmallestRemainingElement (int array[], int size, int index) {
      // do your thing here
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    2
    Sir,
    I still do not undertand. Could you pl be more detailed. I am 77+ and beginner. Would appreciate all help.thanks.KB Iyer

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Wait, you mean you are at least 77 years old?
    That immediately makes me think of this article: Coding Horror: Please Don't Learn to Code

    So, did you see the three line example Salem gave? That's what you need to add to start with. Then you write the code for "do your thing here". You'll also need to write the swap function if you haven't done so already.
    We aren't going to write it for you, so get started on it and show us how you went.
    stahta01 likes this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 11-28-2011, 11:48 AM
  2. Replies: 4
    Last Post: 07-24-2011, 10:38 PM
  3. Replies: 1
    Last Post: 11-15-2010, 11:14 AM
  4. Replies: 3
    Last Post: 10-02-2007, 10:12 PM
  5. Compiler error error C2065: '_beginthreadex; : undeclared identifier
    By Roaring_Tiger in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2003, 02:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21