C++ :: Measure Sorting Algorithm For Performance In Terms Of Number Of Steps And CPU Running Time

May 13, 2014

I have an school assignment that asks me to measure the most famous sorting algorithms for performance in terms of number of steps and CPU running time. ( Here I'm testing for running time)

I decided to test for bubble sort first:

#include <iostream>
#include <ctime>
using namespace std;
void bubbleSort(int ar[], int size) {
int temp;

[Code] ....

So basically what I want to know is:

1. Is this clock function giving the correct CPU running time?

2. Is there any way to write code that would measure the number of steps for each algorithm?

3.I need to test it for number of integers=100 then 200, then 300... Well you get my point, and I don't want to have to actually input 200 numbers with my keyboard. Is there any way to generate as many entries as I want?

View 4 Replies


ADVERTISEMENT

C++ :: Simple Recursive Maze Algorithm And Counting Steps

Jun 1, 2013

My maze algorithm must be able to count total steps. He is not allowed to "jump" from a deadend back to the cross-way he originally came from.

Code:
int R2D2Turbo::findIt(Labyrinth* incLab, int x, int y){
if ((x == incLab->getExit().x) && (y == incLab->getExit().y))
{
return 1;

[Code] .....

Due to the nature of recursive algoirthms, he jumps instead of moving the way back from the deadend one by one... The only solutions I could think of are way overloaded...

View 3 Replies View Related

C++ :: Implementation Running Length Smoothing Algorithm

Feb 7, 2014

I use c++ and opencv. The type of image is Mat structure.

In matlab, I did this :

for i=1:m
for j=1:n
if(image(i,j)==1)
if(one_flag==1)

[Code]....

Another thing is in Matlab the index start from 1 while C++ start from 0.

View 1 Replies View Related

C# :: Running A Class At Design Time

Aug 7, 2014

I have a Class called 'DataManager' which contains a list of my 'DataItem' objects (this are created by an XML file).

I have also created some custom controls which, among other things, has a property to link it to a "DataItem" object.

My question is, is it possible to create an instance of my DataManager class at design time (which runs all the code as it would at run time to create all the DataItems from the XML)?

I want to do this so that I can update my DataItem property in my custom controls to use a UITypeEditor which then allows me to link to a DataItem at design time.

View 4 Replies View Related

C++ :: Running A Procedure Repeatedly After A Set Time Interval

May 28, 2013

I have a certain piece of code that I want to run every 2 minutes. One of my ideas is to get the time and modules that with whatever number represents 2 minutes. Would this work?

View 4 Replies View Related

C++ :: Identify End Of Function Code At Running Time

Apr 16, 2013

I want to implement some "debugger like" tool (very limited one, just identify at running time the current stack trace, and print messages from the user) on some code that the user wrote. what I get from the user is a function name (in the beginning of it's declaration), and when the user want to print some message he uses some print macro I should implement.

My target is printing the stack call, and all the messages that the user wrote, in the right place on the running place.

By what c++ feature can know on running time that a specific function code has ended??

Its easy to push a function to some vector when it called (since I get its name from the user), but when it ends and return to the function called it...

View 14 Replies View Related

C++ :: Chat Messenger - Running Multiple Threads At Same Time

Sep 18, 2013

I'm doing work on chat messenger and facing difficulty to run multiple threads at the same time. Here is the sample code.

void menu();
void groupChat();
void personalChat();
int main() {
sf::Thread thread(&menu());
thread.launch();

[Code] ....

In my program, after menu when he selects a choice, next display of menu wait the termination of the selected thread.
while i want to show menu right after when a menu is selected.

View 2 Replies View Related

C++ :: Linked List Sorting Algorithm?

May 31, 2013

This is the algorithm I have so far and it works great. I was wondering what other people think? Comments/Critiques??

void LinkedList::sort()
{
if (head != 0)
{

[Code].....

View 14 Replies View Related

C/C++ :: Seg Fault In Recursive Sorting Algorithm

Apr 23, 2015

So I am working on a dual pivot quicksort, I can correctly sort the array the first time around however in the main it is called again on the sorted array and in the function I get a seg fault at line 17 in sort.cpp, for the life of me I cant figure it out as the values are the same when I pass it in the first time. Here is the code:

main1.cpp

#include <iostream>
#include "movement.h"
#include "sort.h"
using namespace std;
int main() {
const int size = 10;
T array[size] = {6, 5, 1, 8, 4, 7, 2, 9, 6, 3};

[Code] ....

View 4 Replies View Related

C :: Sorting Algorithm With Dynamic Memory Allocation

Nov 17, 2013

I am fairly new to dynamic memory allocation and I keep getting a segmentation fault in this code of mine. This is what the method should do:void sort StringsByReversePoints(char **myWords): This function sorts the char* values (i.e. strings) of myWords in descending order of point value by calling getWordPoints as a helper function and comparing adjacent words. This simple (but inefficient) sorting algorithm starts at the beginning of myWords array and sweeps to the end comparing adjacent values and swapping if they are out of order. After N (length of the array) sweeps the array is fully sorted. Note that efficiency can be improved by a factor of 2 by shortening each successive sweep by one, since the first sweep will have guaranteed the minimum point value word is the last element of the array, the next sweep guarantees the last two elements are correct, and so on....Additionally, if a given sweep results in zero swaps then the array is sorted and you can return immediately.

View 5 Replies View Related

C++ :: Sorting Data Saved Using Shell Algorithm

Feb 4, 2013

#include <iostream>
using namespace std;
class CD {
public:
static const int num = 100;
char publisher[num], title[num], location[num];

[Code] .....

View 1 Replies View Related

C/C++ :: Sorting Algorithm Program - Split Given String On Commas

Feb 21, 2014

I'm currently trying to code a sorting algorithm program.

let's asume I have a string given: aa, aaa, bbb, bas, zya!

I first of all want to split the given string on commas and '!' tells the program the string ends here and is no part of the last word. lower and upper case is not important at the moment. trying to implement everything with standard libary

output should be like that ofc:
aa
aaa
bas
bbb
zya

I already looked into the bubble sort algorithm and I think it benefits my needs. Just wanted to know how I should start out with the string split.

View 2 Replies View Related

C++ :: List Of Latitude And Longitude Coordinates - Sorting Algorithm

Jul 4, 2012

I have a list of latitude and longitude coordinates which are supposed to trace the outline of a city. Somehow they got scrambled so that they are now out of order. I'd like to write a program to arrange them such that one could follow from one coordinate to the next and trace the perimeter. However, I've run out of ideas for algorithms. What I did so far was a simple search for the nearest coordinate, starting from the first coordinate pair in the array. This produced local regions which worked rather well, but globally there were large jumps as the algorithm ran out of nearby coordinates and was forced to jump across the map.

Is there already a developed algorithm to perform this function?

View 1 Replies View Related

C++ :: How To Calculate Time And Space Complexity Of Algorithm

Jan 25, 2015

define the time and space complexity of an algorithm and about what can i do when the time and space complexity are given and i should write the code corresponding to the restrictions , which i find very difficult.

View 1 Replies View Related

C++ :: Sorting Randomized Array Of Integers Using Bubble Sort Algorithm?

Jun 26, 2013

This program is sorting a randomized array of integers using the bubblesort algorithm.

I am trying to modify n correct the source code,so that the swapping of two values will be done by a function called swap values() by using call-by-reference but function should have as arguments only the two array elements that must be exchanged. (Note: do not pass the whole array to the function!) .We consider an array with the first element containing the number of elements in the array, followed by 10 randomly initialized integers (elements).

The code must sort the 10 elements in ascending order.

Compile: g++ -Wall sorting.cpp -o sorting
*/
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
const int SIZE=10;

[Code] .....

View 1 Replies View Related

C++ :: Bubble Sorting Vectors - Display Highest Temperature And Occurrence Time

Feb 12, 2013

I'm doing a project where I have to store information gathered (temperature and the time it was taken in seconds) in two separate vectors. After an unknown amount of data has been entered, and the end-of-file has been reached, I have to display the highest temperature and the time(s) it occured (bear in mind that the highest temperature may be recorded more than once). The output of that part should be as follows:

Highest temperature: 51
Recorded at time(s):
22:45
2:27

Something like that. The time should also be converted to hours and minutes. To the point: I've done some research on bubble sorting, but they only use it for arrays.

View 3 Replies View Related

C :: Self Balancing Robot / PID Terms?

Oct 23, 2013

Im trying to tune my PID loop to make my robot balance but i dont know if im using the right terms for my robot? Im implementing a contemporary filter for my Gyro(98%) and Acc(2%).Is the following right?

output=(Kp*error)+(Ki*(error*dt))+(Kd*((error-prev_error)/dt))
error=robot angle --Balance point at 0deg
prev_error=--Previous error
dt=0.01 --10ms delay

View 2 Replies View Related

C++ :: Faster Prime Number Algorithm

Oct 19, 2014

Can I possibly get a better implementation of a prime number detecting algorithm than the one I already have below?

Code:
#include <cstdio>
#include <cstdlib>
int main() {
int no, high, low;
int divisor;

[Code] .....

View 8 Replies View Related

C++ :: Algorithm To Get The Decimal Part Of A Number?

Jun 12, 2014

I'm writting an algorithm which equals to std::to_string. The inttostring part is fine, and the decimal_part too. But when the number digits > 5, the program loops infinitely.

#include <iostream>
#include <string>
#include <algorithm>

[Code]...

In this code, the program runs ok. But try to add a 5 at decimal_part. What should I do to get this 'decimal_part' ok?

View 6 Replies View Related

C :: Losing Number In Quick Sort Algorithm

May 16, 2013

I'm tinkering with a serial quick sort algorithm. Normally I use qsort() but I wanted to test this.

Somehow I loose the highest number. I can't see where I drop it.

Code:
// function to quicksort, leave them in front of qsort.
void swap(float_t *left, float_t *right){
float_t temp;
temp = *left;
*left = *right;
*right = temp;

[Code] .....

View 2 Replies View Related

C++ :: Recursive Function To Evaluate First N Terms In Series Specified

Oct 23, 2014

How to remake the code that i`ve written to have : a recursive function to evaluate the first n terms in series specified y= 1 - x + x^2/2 - x^3/6 + x^4/24 +....+(-1)^n x^n/n!

And this is my code:

#include <iostream>
using namespace std;
double power(int n, double x) {
double d =1;
for (int i = 1 ; i<=n ; i++)

[Code] ....

View 12 Replies View Related

C/C++ :: Executable Performance When Using TCHAR

Aug 16, 2014

I have started to move over to using Unicode, wide character null-terminated strings in my Windows programmes. Accordingly I set the Use Unicode Character Set Visual C++ compiler option. It is my understanding that once you do that the many macros which determine whether you transparently call ...A() or ...W() API functions automatically shift over to calling the wide character variants. As this is a compiler directive, all the choices are made and hardcoded in to the resultant executable at compile/link-time BEFORE it is ever run. Therefore using for example the macro OpenFileName() in the source code instead of specifically calling OpenFileNameW() has no impact on run-time performance.

The next logical step, instead of explicitly using wchar_t is to declare null-terminated string character arrays as TCHAR*. Then, so long as I also employ the tcn... variants of CRT string functions and call TEXT() or _T() macros to create string literals the preprocessor will chose, again transparently whether to create an executable using standard multibyte or unicode wide characters - and their associated functions - all determined by the Use Unicode Character Set switch. That way I can cover both eventualities with the same source code.

So, with all that - I THINK!!! - properly under by belt, I am fairly sure that using TCHAR and its friends will not effect run-time performance at all. However, in his otherwise excellent article the author makes it sound as if using Unicode EXPLICITLY through wchar_t, ...W() API functions and tcn... CRT calls is faster than the TCHAR alternative.

At the end of the day my question is - have I got the right end of the stick; TCHAR makes no difference to executable performance?

View 4 Replies View Related

C++ :: Binary Search Algorithm - Find Sum Of Used Number In Sequence

Mar 27, 2014

I have to made a programme which will search for given number and it must work in O(log(n)). The problem is that this programme beside finding this number have to find how many times this given number is used in this sequence.

Sequence is from lowest to highest only one possibility to use binary search algorithm

For example when we have squence
-1 -2 3 3 3 3 4 5 6 7 7 8 9 9 9 9 10

The numbers we need to search are
1 , 3 , 7 , 9 , 11 , 12

The answer is
0 , 4 , 2 , 4 , 0 , 0

So we need to find the sum of used number in sequence.

I have written algorithm Code: int start = 0;
int end = sequencelenght - 1;
int mid = 0;
/// Binary serach
while (start<=end) {
int mid=(start+end)/2;
if (sequence[mid]==givennumber) {

[Code] .....

As u see i search for given numer with binary with O(log(n)) but when i have to sum the duplicates the only good way i see is using loop to right and left but this have got log(n) specification (because when sequence would be for example 7 7 7 7 7 7 7 7 7 and given number to search will be 7 this will be O(n) loop).

How would look the most optimal algorithm look for this exercise? I mean O(log(n)) the fastest algorithm....

View 6 Replies View Related

C++ :: Count Number Of Distinct Edges Using Set Based Algorithm

Sep 8, 2014

So I have this set

13
14
24
31
62
35
36
42
13
44
62

now using sba or Set Based Algorithm I have to pair it out and towards the end find the size of the resulting set

#include <iostream>
#include <set>
int main()

[Code]......

this is the code just reads the edges that's 3... that is when we input the code. But what if its in a file? how do I read from there and show the paired count and the time taken?

Also I have the file that works and reads any txt file..but how do i get the code from it?

[URL]

this is the file..you have to run it as ./edgecount for it to work

View 1 Replies View Related

C Sharp :: Maintain Temperature Of Grill And Measure Temperature Using Probe At 12 Points

Jan 16, 2013

I have to write a program for a restaurant and their food has to be cooked on a hot sheet of metal and too cook their burgers properly I must keep a maintain temp of 400 F, for the grill and to measure the temperature using a probe at 12 points, there are 3 elements with 3 points on them

View 2 Replies View Related

C++ :: Storing 10 Elements In Array And Delete Duplicate Terms

Jul 19, 2014

How to store 10 elements in an array and delete the duplicate terms ? ( its a single dimension array )

View 5 Replies View Related







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