C/C++ :: Sorting Algorithms And Comparison Count

Jan 30, 2014

I am trying to count the number of comparisons for each of the following sorting algorithms, Selection, Insertion, Bubble, Merge, and Quick sort. This is using an array of numbers that are sorted, reversed, and randomly arranged.

I currently increment the "number of comparison" variable before every conditional statement that compares two numbers and am getting the following results:

Number of Items in Array = 100
Selection: random = 5049; reverse = 5049; sorted = 5049;
Insertion: random = 2640; reverse = 5049; sorted = 99;
Bubble: random = 9207; reverse = 9900; sorted = 99;
Merge: random = 1221; revere = 988; sorted = 1028;
Quick: random = 690; revere = 587; sorted = 636;

View 1 Replies


ADVERTISEMENT

C++ :: Sorting A Map By Custom Comparison?

Jan 8, 2012

so i have a std::map like this:

map<DWORD,DWORD> mymap;

now i want to sort it by the second DWORD value, and thus i have to implement my own comparison function and use sort() from <alogirthm>:

Code:
bool y(const map<DWORD,DWORD>::iterator& a, const map<DWORD,DWORD>::iterator& b)
{
if(a->second < b->second)
return 1;
else
return 0;
}
...
sort(mymap.begin(), mymap.end(),y);
...

but this throws thousands of errors at me, including C2784.

View 14 Replies View Related

Visual C++ :: Program That Count From 1 To 12 And Print Count And Its Square For Each Count

Dec 16, 2014

4.1 Write a program that will count from 1 to 12 and print the count, and its square, for each count.

4.2 Write a program that counts from 1 to 12 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.

4.3 Write a program that will count from 1 to 100 and print only those values between 32 and 39, one to a line. Use the incrementing operator for this program.

View 2 Replies View Related

C++ :: Some Algorithms For Compressing Images?

Feb 16, 2014

RLE(Run Length Encoding)
using namespace std;
class Bitwriter{
private:

[Code]....

View 1 Replies View Related

C/C++ :: Analysis And Evaluation Algorithms?

Mar 25, 2015

#include <iostream>
#include <vector>
#include <list>

[Code].....

The problem is it's not finding the shortest path.

View 1 Replies View Related

C :: Time Scheduling Algorithms Program

Jan 20, 2014

I am an IT college student and this is a self-assigned project i have done in an attempt to learn programming in C AND at the same time how time scheduling of an OS works (Both done in order to prepare for upcoming semester exams) using FCFS ,SJF, RR and PS algorithms (planning on adding SRT too sometime soon). (took me 9 hours total work time including validations). What i wanna know is from more seasoned coders if i am on the right track. *cross fingers*

Code:

#include <stdio.h>
#include <stdlib.h>
#define P_Q 1000

int main(int argc, char *argv[])
{
float min_value,
}

[code]....

View 11 Replies View Related

C++ :: Text Editor Printing Algorithms?

Mar 26, 2013

They should apply for: backspace, return, regular char input, vertical scrolling. There is only one buffer, and it is not allowed to side scroll past max col, instead it must scroll down, appending the line cur_y + 1.

View 4 Replies View Related

Visual C++ :: Analysis And Evaluation Algorithms

Mar 25, 2015

Undirected graph G = {V, E} is given by the list next to the DS. Let u, v of V. Construction of two paths algorithm A1 (u, v) and A2 (u, v) such that no edge in common and have the shortest total length.

View 1 Replies View Related

C++ :: Multi-level Algorithms For Date-driven Scheduling

Apr 18, 2012

What is Multi-level algorithms for date-driven scheduling?

View 8 Replies View Related

C++ :: Output Compiled Script Into Binary File - Scripting Tool Algorithms

Dec 25, 2014

I am working on a script compiler that must output compiled script into binary file. Compiling etc is not a problem. The problem is detecting some specific cases. Nothing seems to work. If it works, then it breaks as soon as i modify the script.

Here is example "script1":

Code:
1VAR1 c1 = 44
2VAR2 c2 = 66
3beginscript
4if(c1=44)
5do_nothing

[Code] ....

Second example "script2", when there can be also some command between ENDIF and ENDIF. In this case: do_nothing command.

Code:
1VAR1 c1 = 44
2VAR2 c2 = 66
3beginscript
4if(c1=44)
5do_nothing

[Code] ....

The INDEXES before each line are not in actual script. They are just to point YOU to specific lines. Although the INDEXes are in compiled script!! This is very important. As you see there can be simple IF_ENDIF and nested (more complex) IF_ENDIF.

i.e IF_ENDIF inside another IF_ENDIF.

There are also IF_ELSE_ENDIF and some other ones, but im trying to make simple IF_ENDIF work first.

ENDIF is "SPECIAL" command, the IF, DO_NOTHING are "usual" commands.

"Usual" commands must always jump over(!) the ENDIF. ALWAYS!!

They must "ignore" them!

One strong RULE is like this for usual commands: always jump over any ENDIF, not matter what. If there is one, two or more ENDIF's in a row, then just jump over them to the closest NEXT usual block command. If there is some "usual" block command between multiple ENDIFs, then jump to this command and this command must therefore check whats next command right after it. And do the same: check if next command is ENDIF, if yes, jump over it, until "usual" block command is found.

This is the place im stuck. When i some time ago thinked about some ideas, i saw some patterns. One of them was that: Seems like if its nested IF_ENDIF, then every usual block command jumps out of it, i.e. right after the final ENDIF of this current nested IF_ENDIF.

But as soon as i added do_nothing between the two ENDIFs the so called "pattern" broke. In script2 above you see index 11 is do_nothing. Ok its in nested IF_ENDIF it should jump out to command index 17. But no, because there is do_nothing between index 13 and 16. If we jump out at index 11, the command 14 would never execute. This is a BIG NO. One idea i was thinking and trying was to use STL::FIND, STL::FIND_IF to find next "usual" command after specific index. But my code seems to crash sometimes and not work always.

Code:
bool NextNonENDIF(int i) {
return (i!=98);
}
int findNextBlockCmd(vector<int>&vec, int curidx)

[Code] ....

Here i pass him the vector that contains all the command TYPES in current script. Each command has its own TYPE or better called unique ID in which way compiler knows what is what. So in this case im trying to find a command thats NOT "ENDIF", in other words im trying to find next usual command after specific type of command. Lets just say the TYPE or unique ID of do_nothing is 555, im trying to find it.

How i should continue with this? What to use maybe stl::stack, some custom command indexing, some sort of labelling for usual commands in nested IF_ENDIFs or what?

In general, look script2, and i ask: There is index 11, this guy should look if there is any usual block command left for him before the final ENDIF at index 16. If there is, jump to it. If there is none, jump out of this nested IF_ENDIF to index 17.

Question: how to do it? What algorithms to use? I can use STL, BOOST, whatever. And i can use C++11.

View 1 Replies View Related

C++ :: Comparison Of Two XML Files?

Feb 2, 2015

I need a program that can compare two xml files for equivalency using any XML Parser.

View 2 Replies View Related

C/C++ :: Comparison Of Excel And CSV

Mar 6, 2012

I have to compare data in excel and csv based on the file name and update the status of file from CSV into excel file by creating a new column status on weekly basis.

View 1 Replies View Related

C++ :: Overloading Comparison Operators For Using In A Set

Oct 30, 2014

I have a small piece of code that used the set::insert function on a set of myClass. For that, I need to overload the < and > operators, which I have, but I still get a huge error saying it can't compare.

set<MyClass> mySet;
MyClass myClass

All the class information gets filled in. Then, I try to insert...
mySet.insert(myClass);

bool operator<(MyClass &lhs, MyClass &rhs) {
return lhs.name < rhs.name; //name is a string
}

The error says
...stl_function.h:230:22: error: no match for 'operator<' in '__x < __y'
MyFile.h:80:6: note: candidate is bool operator<(MyClass&, MyClass&)

View 5 Replies View Related

C++ :: Vector Comparison Out Of Range?

Jul 31, 2013

I'm making a simple game and I'm having trouble creating boundaries for the players movements. The map is a 2D vector. When I compare the vector with the players current position sometimes I get an error during run. When the error isn't occurring the behavior of the boundaries is bizarre. The error tells me that the vector is out of range.

Here is the where the map is created. It's within its own class constructor.

vector< vector<char> > map_parts;
map_parts.resize(25);
for ( int i = 0; i < 25; i++ )
{

[Code].....

View 1 Replies View Related

C++ :: Comparison With Uppercase / Lowercase?

Jul 28, 2014

I have this statement - while(strcmp(x[i],"Stop")!=0); - is there anyway to compare x[i] to all the possible forms of "stop" (Stop, STOP, sTop, etc)?

View 4 Replies View Related

C/C++ :: Overloading Comparison Operators

Aug 28, 2014

I made a program that allows the user to enter information of credit cards on an array of size 5, however I need to allow the user to compare the five credit cards with each other and I am having problems with this particular part. I made my bool operator functions for the operator< and the operator> but how to make the user be able to select which cards he wants to compare and how to compare them. My code is the following:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int SIZE = 5;
enum OPCIONES {CARGAR=1, ABONAR, NADA};

[Code] ......

View 2 Replies View Related

C/C++ :: ISO Forbids Comparison Between Ptr And Int For Types

Jul 14, 2014

This is some code that simulates files and directories the same way an operating system does so. I commented out every std::string occurrence because I got the :

terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create

View 3 Replies View Related

C++ :: One Letter Of A String Comparison

Jan 21, 2013

I just would like to turn this into cpp:

string eg("azertyFTW");
if(eg[one of the letters contained in this string] == 'c') {
cout << "eg has the letter c in it";
} else {
cout << "not this time :(";
}

View 4 Replies View Related

C++ :: Comparison Of Two Strings (case Insensitive)

Apr 27, 2013

bool simpleQuestion::checkAnswer(string guess) const {
for (int i=0;i<qAnswer.length();i++)
if (qAnswer==guess)
return true;
else
return false;
}

This is my code and what im trying to accomplish here is making the comparison of the two strings (qAnswer & guess) case insensitive. I know i need to loop through each character of each string and for each character i can use toupper and every char in each string will become uppercase and therefore case insensitive. However, im not sure how to go about this; if any technique used to loop through each character of the string and how to use to upper.

View 2 Replies View Related

C++ :: ISO Forbids Comparison Between Pointer And Integer

Apr 21, 2013

I am trying to make a program that prints out an 8 by 8 board with 1 queen on each row.

For example, if the user enters: 0,3,4,0,0,7,6,7

the program should create following board and print:

Q.......
...Q....
....Q...
Q.......
Q.......
.......Q
......Q.
.......Q

I think I am doing it right but im getting a couple of errors that i cant fix ...

#include <iostream>
using namespace std;
int main(){
int x [8] [8], r, c;
for(c = 0; c <= 8; c++){
cout << " Enter a number from 1 to 7 " << endl;

[Code] .....

these are the errors :

assignment15_meem.cpp: In function âint main()â:
assignment15_meem.cpp:7: error: no match for âoperator>>â in âstd::cin >> x[c]â
assignment15_meem.cpp:10: error: ISO C++ forbids comparison between pointer and integer

View 7 Replies View Related

C/C++ :: ISO Forbids Comparison Between Pointer And Integer

May 4, 2014

template <class ST>
bool OrderedSet<ST>::IsIn (const ST & value) const {
for (LNode * np = first; np != NULL; np = np -> next)
if (np -> next == value)
return true;
return false;
}

View 1 Replies View Related

Visual C++ :: Comparison Of 2 Double Values

Dec 27, 2013

I have std::vector of players and each player have its own value. The value is of the type double, but the original value are of the "XX.00".

Now what I'm trying to do is to insert a player into this vector. For that I need to find a place and to find a place I need to compare player value.

So lets say I have a player in the vector whose value is 24.00 and I am trying to insert a player whose value is 25.00. To my surprise MSVC 2010 tells me that:

24.0000000000000 == 25.00000000000

I do aware that comparing double type is not going to work like this, but I would expect not to have such big of a difference. ;-)

Why this comparison is true and how to eliminate such thing?

View 3 Replies View Related

C++ :: Map Comparison Fails In Function Const

Jan 27, 2012

Why I'm getting an error here. I've dumbed down my code for simplicity and removed irrelevant code.

PHP Code:
class Foo {
    public:
        bool IsNull() const;
    private:
        std::map<int, int*> test;

[Code] ....

I'm getting a "passing...discards qualifiers" error on my if statement and not sure why because I'm not changing anything. I know removing const or making test mutable fixes the issue. I've been taught to always make a function const if it doesn't change anything, in which case, have I finally come across an acceptable time to use mutable?

View 9 Replies View Related

C++ :: How To Compare Two Files And Display Their Comparison Percentage

Feb 10, 2013

How to compare two files(two texts documents) and display their similarity percentage by using C++?

View 10 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++ :: String Comparison - Case Insensitive Program

Feb 20, 2014

So I have started this program for class but am stuck on what to do next. Basically you need to create a function to compare 2 strings (case-insensitive). The strings shouldn't be altered and the return value should be similar to strcmp.

This is my main file

#include <iostream>
//#include <cstring>
#include <iomanip>
#include "rpstrings.h"
using namespace std;
int main () {
char Str1[20], Str2[20];
short result;

[Code] .....

I don't know if I labeled the files correct. what I need to do is to add 2 defaulted arguments which will allow the user to request that you skip spaces and/or skip punctuation when doing the comparison.

Also, how I can sort the numbers when they aren't justified with leading 0's and if they aren't in the lead string (kinda of like the natural sort).

View 2 Replies View Related







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