C :: Selection Sort Program Crashes Right After Value Entered

Mar 25, 2014

I'm trying to code a Singly-Linked List(Double Pointers) selection sort program and I can't tell what the problem is. My compiler says no errors but when I run the program, it crashes right after I enter the values.

Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

typedef struct node{
int elem;
struct node* link;

[Code] ....

The compiler that I'm using is Dev-C++.

View 2 Replies


ADVERTISEMENT

C/C++ :: Bubble Sort And Selection Sort?

Feb 19, 2014

You will write a program that uses a multidimensional array having 3 rows and 8 columns and sorts each of the rows using both a bubble sort and a selection sort.

You must declare the array inside of main. You will have a for loop containing the calls to bubbleSort and selectionSort. You need to pass into function bubbleSort and selectionSort the following: 1) each column of the multidimensional array, 2) the size of the column, and 3) a particular row number of the multidimensional array to be used for printing out the "pass" shown on the following pages.

I keep getting an error that the identifier for bubbleSort and selectionSort is not found. (Error C3861) Also, I feel like I'm missing something in int main() to get it to sort properly.

# include <iostream>
using namespace std;
int main()
{

[Code].....

View 14 Replies View Related

C :: Implementing Selection Sort Algorithm

Jun 14, 2014

So i'm trying to implement the selection sort algorithm and it seems that the code is fine but...

Code:
#include <cs50.h>
#include "helpers.h"
void
sort(int values[], int n) {
// TODO: implement an O(n^2) sort

[Code] ....

I keep getting these errors and i don't understand why:

/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

View 3 Replies View Related

C++ :: Selection Sort 2D Char Array

Feb 18, 2014

How to sort the last name instead of first name. Everything works so far and sorting is done on the first character.

#include <iostream>
#include <cstring>
using namespace std;
void sort(int, char[10][40]);
int main() {
char twoD[10][40];
int input = 0;

[Code] .....

View 4 Replies View Related

C :: Sorting Strings Using Selection Sort Method?

Dec 7, 2013

I am trying to write a program to sort the characters in a word alphabetically. For example, if you input 'what', the computer will sort it into 'ahtw'. But, it fails to work. I didn't know why.

Code:

#include <stdio.h>
#include <string.h>
main() {

[Code].....

View 8 Replies View Related

C++ :: Calculate Total No Of Comparison Using Selection Sort?

Sep 15, 2014

how to put comparision condition in order to caculate total number of comparision in selection sort

static void selectsort(int[] data, int n)
{
int i, j;
for (i = 0; i < n; i++)

[Code]....

View 1 Replies View Related

C++ :: Selection Sort On Array Of Class Objects?

Jan 24, 2013

I have written a selection sort algorithm to go sort an array of class objects by age in ascending order, the problem is that the output being given does not match what i think the code should do. when the program runs the 3 records are added to the array and when they are sorted should be outputed in ascending order, the problem is that with my code the last 2 are sorted properly but the first element does not seem to move, it remains the same as the original unsorted value.

My code for the selection sort function and the display method are below:

void selectionSort() {
int i, minIndex, minValue;
for (i = 0; i < (arrlength - 1); i++) {
minIndex = i ;

[Code].....

View 1 Replies View Related

C++ :: Selection Sort For Non Decreasing Order Input?

Feb 17, 2013

Question: What is the efficiency and big O of the selection sort algorithm when the input happens to already be in nondecreasing order?

Answer: Not sure... since the input is in nondecreasing order, such that example 0, 1, 1, 2, 3, 4, 4, 5 then there will be no swap, Just comparisons of emelemts. So it is big O of n

View 2 Replies View Related

C++ :: Sorting With Selection / Insertion And Bubble Sort

May 4, 2014

This program using the selection, insertion, and bubble sorts. The program needs to be able to do the following:

1. Create an array of 1000 population records when the array object is instantiated. Call it unSorted.

2.Open the file called "Population.csv" (on the portal) and invoke a function that loads the population data into the array.

3.Create a second array of 1000 elements that will be used to sort the data using the different algorithms. Name is sortedArray.

4.Write a function that will copy unSorted into sortedArray and execute that function.

5.Using a function, display the unsorted array.

6.Invoke the insertionSort () function that will sort the sortedArray using the insertion sort algorithm. Sort the population data on the rank field in ascending order. Alternatively, you can sort in descending order on population.

7.Using the display function, display sortedArray.

8.Display the number of iterations it took to do the sort using this algorithm.

9.Repeat steps 4-8 for the selection and bubble sort algorithms.

Here is my code so far:

Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void loadArray (int unSorted[], int s);
void displayArray (const int num [], int size);

[Code] .....

Here is a few lines from the Population.csv file contents:

Code:
Alabama,Baldwin County,140415,389
Alabama,Blount County,51024,908
Alabama,Calhoun County,112249,477
Alabama,Colbert County,54984,858
Alabama,Cullman County,77483,653
Alabama,Dale County,49129,927
Alabama,Dallas County,46365,974
Alabama,DeKalb County,64452,753

I'm not sure how to load the data from the file into the array properly, I attempted this. I also don't know how to copy the unSorted into sortedArray.

View 14 Replies View Related

C :: Selection Sort Algorithm For Singly Linked Lists

Feb 24, 2013

I've written code for a selection sort algorithm to sort through a singly linked list, However, it only brings the smallest node to the front, but doesnt swap positions of any of the remaining nodes, even though they are not in order.

Input list: 3 6 17 15 13 15 6 12 9 1 2 7 10 19 3 6 0 6 12 16

Sorted list: 0 6 17 15 13 15 6 12 9 1 2 7 10 19 3 6 3 6 12 16

Code:

#include<stdio.h>
#include<stdlib.h>
struct node{
int val;
struct node *next;

[Code] ......

View 1 Replies View Related

Visual C++ :: Multidimensional Array Having 3 Rows And 8 Columns - Bubble And Selection Sort

Feb 19, 2014

You will write a program that uses a multidimensional array having 3 rows and 8 columns and sorts each of the rows using both a bubble sort and a selection sort.

You must declare the array inside of main. You will have a for loop containing the calls to bubbleSort and selectionSort. You need to pass into function bubbleSort and selectionSort the following: 1) each column of the multidimensional array, 2) the size of the column, and 3) a particular row number of the multidimensional array to be used for printing out the "pass" shown on the following pages.

I keep getting an error that the identifier for bubbleSort and selectionSort is not found. (Error C3861)

Also, I feel like I'm missing something in int main() to get it to sort properly.

Code:
# include <iostream>
using namespace std;
int main() {
const int SIZE1 = 3;
const int SIZE2 = 8;
int arr [SIZE1][SIZE2] = { { 105, 102, 107, 103, 106, 100, 104, 101 },

[Code] ....

View 1 Replies View Related

C :: Recursive Crashes Program?

May 13, 2014

cause I cant find why it crashes. It compiles without any error,but crushes when i run it and I can't find where is wrong the code.

Code:

#include <stdio.h>
#include <time.h>
#include <math.h>

[Code].....

View 7 Replies View Related

C/C++ :: Program Crashes When Try To Remove Item?

Sep 28, 2014

In my program, I am trying to implement a set in which I can add/remove and print, it doesn't have to be a specific value removed just that it removes an item from the list. When I call the removeItem function it crashes, saying my iterator is out of range. I don't understand what is wrong. Here is my code:

#include "stdafx.h"
#include <iostream>
#include <set>

[Code].....

View 4 Replies View Related

C/C++ :: Program Crashes When Records Greater Than 10

Feb 17, 2015

I've implemented a records system for a college assignment and everything works as intended. However upon increasing the amount of records to store in my array above 10, the program crashes upon adding a new employee and I can't work out why...

#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define esize 10 /* Change max-records */

[Code] .....

View 3 Replies View Related

C/C++ :: Cannot Add New Variables To Program - Crashes After Compiling

Oct 24, 2014

Problem: When I add a new variable to complete my program, it crashes. I have tried tracing where the problem is but it leads to adding new variables

Purpose of program: Every 2 lines of the input file belong to 1 participant. The line with decimals include times a person has run miles. While the second line of each participant are integers that indicate the best sets from workouts the participant had done.

so an example of the output

Participant #1
Cardio Workouts:
Best Time:
Worst Time:
Average Time:
Weight Workouts:
Most Sets:
Least Sets:
Average Sets:

Participant #2
...

Why my program is crashing

#include <stdio.h>
int main () {
// Stats Col0=BestTime Col1=WorstTime col2=mostSets col3=leastSets Col4=Average_time Col5=Average_sets
float chart[20][12], stats[10][6], best_time=100, worst_time=0, most_sets=0, least_sets=100, avg_time, avg_sets, sum;
int i, j;
int p=0;

[Code] .....

Attached File(s)
input1.txt (817bytes)

View 1 Replies View Related

C++ :: Program Crashes While Printing Data From Vectors

Nov 23, 2013

I have a local student and international student class inherit from student class. read and print are virtual functions. After i have set all the member variables when i wan to print out all the student information, my program crashes.

Code: int main()
{
clsUniversityProgram objProgram[3];
for (int x = 0; x < 3; x++)

[Code] ....

View 4 Replies View Related

C++ :: Program Crashes After Input - Terminated Called

Oct 28, 2013

My programs complies and runs. However, whenever i try to enter something when prompt to enter the number of accounts i wanted to create my program crashes.

By the way, im using codeblocks.

it says

terminated called after throwing an instance of 'std:: out of range'. what(): basic_string::substr"

Code:
#include <iostream>
#include "clsInterest.h"
#include "clsDate.h"
using namespace std;

[Code] .....

View 8 Replies View Related

C :: Program Crashes When Parsing Musical Notes From It

Jul 23, 2013

I have the text parser done, but when I use it, the program crashes. Just because of how I test my code, I know the section where it occurs, but I'm not sure what the exact problem is ( no errors or warning, so it's just something I don't see ). Here is the full code

Code: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

[Code].....

I probably made a mistake in the way I allocated memory or tested values, but I'm not sure where it is in my code. Currently it just prints out "Failed to parse data on line 1" then crashes. Here is the text file I give to this program.

Code:
A#3 500 A#3 500 A#3 500
rest 1000
B#4 500 C3 500

View 7 Replies View Related

C++ :: Fseek - Program Crashes And Stops Responding

Feb 9, 2015

i wrote a little program with fseek. It works good till it reaches the first fseek(). Then it crashes and stops responding.My code:

ifstream inp("myfile.txt");
if(!inp.is_open()) return false;
inp.close();
FILE *f;
fopen("myfile.txt","rb");

[code].....

View 2 Replies View Related

C++ :: Delete Operator Is Not Working - Program Crashes At The End

Jan 12, 2013

int main() {
int vnum = 0;
VEHICLE *vehiptr;
VEHICLE *dptr;
cout<<"Please enter the number of vehicle: ";
cin>>vnum;
vehiptr = new VEHICLE[vnum];

[Code] .....

View 9 Replies View Related

C/C++ :: Program Crashes After Numbers Input From User

May 6, 2014

#include <iostream>
#include <string>
#include <limits> //for std: numeric limits
#include <algorithm>
//Function to get an integer from the user that is greater than or equal to zero.

int getPositiveIntFromUser(const std::string& prompt) {
int retVal = -1;

[Code] ....

The first part works, but it doesn't calculate the GCD or LCM at all, it just crashes!

View 2 Replies View Related

C++ :: Selection Process Using Roulette Wheel Selection?

Feb 9, 2013

I'm trying to make a selection process using roulette wheel selection. To do this I created two matrix, one random probabilities and one increasing probabilities. The idea is to choose a number according to the random probabilities. Here is the code I've written.

#include <iostream>
#include <conio.h>
#include <cstdlib>
using namespace std;
int main (){
float select [5], prob [10], mat [5];
int c, r, z;
cout.precision (2);
cout << "Random Number:" << endl;

[Code]...

The result I got is as follows:

Random Number:

0.0013 0.56 0.19 0.81 0.59

Increasing Probabilities:

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Selected Column:
0
5
6
8
9

The evaluation doesnt seem to start from c=0 again. The selected column should be 0, 5, 1, 8, 5.

View 6 Replies View Related

C :: Program Crashes And Returns Random Negative Numbers

Mar 1, 2014

I having some issues with two different programs here... One of them crashes and returns random negative numbers whenever it reaches a "fscanf" function and the other displays a "Polink fatal error: access denied" error.

Code:
/* Evan Wentz */
/* Pike - ET2560 */
#include <stdio.h>
#define MAX_ACCTS 100

int accounts [];
double balances [];

[Code] ....

I thought the reason this kept crashing before was because I didn't type the data into the text file it was writing too correctly, but I made another program to do that, and it crashed whenever it got to fprintf. Program works perfect besides the file stuff...

View 6 Replies View Related

C++ :: Program Crashes When Reading Linked List From File?

May 5, 2013

Why program crashes when reading linked List from file?

#include <iostream>
#include <fstream>
using namespace std;
struct link{
int data;
link* next;

[Code] .....

View 4 Replies View Related

Visual C++ :: MFC DLL To Interact With API - Program Crashes After Displaying 100 Bars?

Apr 27, 2013

I have written a MFC dll to interact with an API and it is run by the target program. the first 100 bars are drawn properly but then the program ceases to operate. I am guessing I have a memory leak but I probably just dont understand what I am doing as I am quite new to programming MFC GDI. Here is my code that causes the trouble...

The variables coming in are commented out to facilitate testing and so it would be displaying the same bars over and over because of this. it worrks for 100 bars, then crashes.

void MainDlg::SS_UpdateChart() {
// the chart plot is completely recalculated each time a new bar is shown
// 300 is plottable height
// 400 is plottable width, 39 bars
int displayChartHeight = 300;

[Code] .....

View 11 Replies View Related

C :: Reversing Every K Nodes Of Linked List - Program Crashes While Running

Mar 11, 2013

The code below is for reversing every k nodes of the linked list. While running the Program it crashes.

Code:
#include<stdio.h>
#include<stdlib.h>
struct node {
int info;
struct node *next;

[Code] ....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved