Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C++ I need a code for hangman using insertion sort and linear search

asking for someone to code for i am new to C++
lol.. good luck with that mate. I highly doubt anyone here will do your homework for you. Now, if you attempt it, and can't figure it out, then sure, you're gonna get plenty of people to help you out, as long as they can see that you actually tried. I get it... you're new to the language, and have all sorts of questions. That is normal... but don't confuse laziness for frustration
 
Hi unc,

i recommend that you first learn the basics of the c++ programming language.
The insertion sort algorithm can look like this:

C++:
#include <iostream>
using namespace std;

void swapElements(int *a, int *b) {
   int temp;
   temp = *a;
   *a = *b;
   *b = temp;
}

void insertionSort(int array[], int length) {
    int i, j, k;
    
    for (i = 1; i < length; i++) { 
        k = array[i]; 
        j = i - 1; 

        while (j >= 0 && array[j] > k ) { 
            array[j +1 ] = array[j]; 
            j--;
        } 

        array[j + 1] = k; 
    } 
}

void printArray(int array[], int length) {
    for (int i = 0; i < length; i++) {
        cout << array[i] << " ";
    }
}

int main() {
    int arrayLength, i;
    int myArray[20];

    cout << "How many numbers do you want to store in array? (1 - 20) " << endl;
    cin >> arrayLength;

    // Store numbers in array (user input)
    for (i = 0 ; i < arrayLength ; i++) {
        cout << "Please enter a number:" << endl;
        cin >> myArray[i];
    }

    cout << "Array before sorting:\t";
    printArray(myArray, arrayLength);

    insertionSort(myArray, arrayLength);
    cout << "\nArray after sorting:\t";
    printArray(myArray, arrayLength);
    

    return 0;
}

Quelle: Codevisionz
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom