C++ :: DFS Algorithm Malfunction - Graph Is Consistent

Apr 18, 2012

I wrote class DFS - Depth-first search. This algorithm check that this graph is consistent. Below is code of class

Code:
#ifndef DFS_H
#defineDFS_H
class DFS{
private:
std::stack<int, std::vector<int> > stos;//stos do przechowywania wezlow w dfs'ie
int *odwiedzony;
int liczbaWezlow;

[Code] ....

When i initialize dfs i use 2 parameters. On the next step i would like show all content array odwiedzony. Regardless of the given parameters of the array always has a value of zero. Where i made mistake and how to repair?

View 10 Replies


ADVERTISEMENT

C++ :: Graph Search Algorithm - Recursion Using Stacks

Mar 22, 2013

Any example of a graph search algorithm that uses a recursion and linked list based stacks to determine a route from a single point on a graph to another single point on a graph?

View 3 Replies View Related

C++ :: Boruvka's Algorithm - Find Minimum Spanning Tree Of A Graph

Apr 10, 2014

I am trying to implement Boruvka's algorithm to find the minimum spanning tree of a graph but my program crashes in the find function when i run it.

[URL] .....

sample input : [URL] .....

View 1 Replies View Related

C++ :: Dijkstra's Algorithm - Find Shortest Path In A Dense Graph

Apr 19, 2012

Code that finds a shortest path in a dense graph, using Dijkstra's algorithm in the simple array version. You write a function

struct listnode shortest path(int n, int s, int t, int *dist)
with
struct listnode f struct listnode * next; int vertexnumber; g ;

Being used to return the list of vertices on the shortest path. Your function has the following arguments:

- n: the number of vertices of the graph,
- s: the start vertex,
- t: the target vertex
- dist: the matrix of edgelengths.

The vertices are numbered from 0 to n -1, so s and t are numbers in that range. dist is a pointer to the n * n matrix of edgelengths; vertices which are not connected will be joined by an edge of length 9999. To access the array element dist[i][j], we can use *(dist + i*n + j). Your function should return the list of vertices on the shortest path from s to t, starting with s and ending with t.

View 4 Replies View Related

C++ :: Consistent Random Numbers Across Implementations

Mar 5, 2014

If I seed with the same seed I want the same sequence of numbers no matter if I use GCC, Clang, VC++ or Windows, Linux, Mac. I think this is guaranteed by the standard engines in <random>.

I also want to be able to save the state of engines and restore them in a program compiled with a different compiler. I have been under the impression that the stream operators for the standard engines did not guarantee this kind of compatibility across implementations but after looking a bit closer I think it should work, assuming obvious stuff like CHAR_BIT == 8 and that the same character set is used.

When it comes to distributions like std::uniform_int_distribution and std::geometric_distribution I don't think I can rely on a consistent behavior. It looks like the standard only say what probability density function they should have. It doesn't explain how exactly the output should be calculated from the number that the engine produce. For this reason I don't think I can use any of the distributions in the standard library if I want a consistent sequence of numbers everywhere.

So am I correct that I can safely use the standard engines as long as I don't use the distributions? Or do I have to use a library with a fixed implementation to guarantee this to work consistently across compiler implementations?

View 3 Replies View Related

C++ :: Getting Consistent Type Names Under Windows And Linux?

Dec 4, 2014

I'm writing a server/client application in C++, one linux and one windows. The generic communication method is to use the boost::serialization package, but I'll also use a header to distinguish the type of the serialized string.

Here is the struct that the two programs communicate with

struct SerializeString {
std::string type_name;
std::string serialized_string;
friend class boost::serialization::access;
template<typename Archive>
void serialize(Archive& ar, const unsigned version) {
ar & type_name & serialized_string;
}
};

When one side wants to pass an object to another side, it uses typeid(T).name() for the field type_name. The receiving side receives SerializeString and checks its type_name against various acceptable structs as follows:

if (ss.type_name == typeid(XXX).name()) {
// deserialize ss.serialized_string to XXX and do something with it
} else if (ss.type_name == typeid(YYY).name()) {
// deserialize ss.serialized_string to YYY and do something with it
} else if (ss.type_name == typeid(ZZZ).name()) {
// deserialize ss.serialized_string to ZZZ and do something with it
} else {
// etc...
}

This worked fine when I was using Windows VS2013 on two different windows platform. However when I switch one to Linux there is a problem because their typeid(XXX).name() returns different things. So question here, is there a generic way to get some sort of unique names across platform / compiler? Or is my method reasonable at all?

View 7 Replies View Related

C++ :: Asterisk Bar Graph

Feb 12, 2014

i have to make a programs that prompts the user to enter quiz grades and add them up. For examples the user enters 6 test grades they are out of 5 so he enters 0-5 and i store them in the array. This part works great but now i have to print out a bar of vertical asterisks for every part too. So if at the end we have one test grades that are 2 grades of 1 points, 1 grade of two point, 2 grades of three point and 1 grade of 5 point it will have to display them as this

There are 2 grades of 1
There are 1 grades of 2
There are 2 grades of 3
There are 1 grades of 5

i need to do for loops but i am stuck on what to count too and what to print i know i will need cout << "*" and a couple of spaces.

#include <iostream>
using namespace std;
int main (){
int size;
int tests;
int a[6]={0};

cout << "How many quiz scores will you enter: ";
cin >> size;

[code]....

View 1 Replies View Related

C :: Depth-first Search Of A Graph

May 18, 2013

You have to implement a data structure to represent graphs,directed or undirected,that tries to avoid the wasted space in the representation of a graph with adjacency matrix and the difficulty of searching the edges with adjacency list representation.We consider that the vertices are numbered from 1 to nverts and the exit degree of each vertex is at most MAXDEG. If deg[i] is the exit degree of the vertex i then the neighbors of the vertex i can be saved at the matrix edge[i][j], 1<=j<=deg[i].

Write a program that reads the datas from a file: if the graph is directed or undirected(1 or 0), the number of vertices (nverts),the number of edges (nedges) and the first and the last vertex of each edge.Write the function dfs that, with argument the data structure that you implemented before for the representation of a graph, prints the edges by the depth-first search of a graph. What I've done so far is: I wrote a program that reads these information from a file, calculates the exit degree of each vertex and creates the matrix edge[i][j]. What data structure do I have to implement???

View 1 Replies View Related

C :: Program Finding Max Of Graph

Oct 29, 2013

this is my first year programming, and in my class, each week we have to write a program. last week we wrote a program in c that made random value point and made a graph of the random points that continued on forever. this week, we have to use statistical functions to find the sum, mean, max, and min of the graph. below is the code i have so far.

Code:

#include <stdlib.h>
#include <strings.h>
#include <stdio.h>
#include <stdbool.h>
#include "SwinGame.h"

[code]....

so, as you can see from the code, the parts i need are finding/ coming up with a function to find the max min sum and mean of the functions.

View 7 Replies View Related

C :: Create ASCII Bar Graph Of Die Rolls

May 24, 2013

for an assignment we need to create basically a program that asks the user for the result of standard six-sided die rolls (numbers from 1 to 6). The program will prompt the user with "Enter a die roll or 0 to exit " for the first entry and Next die roll? for all subsequent entries. The program will continue reading die rolls from the user until the user enters 0. At this point, the program prints two newline characters (one blank line) and finally, the bar chart showing the number of times each die roll has been entered, and then terminates.If the user enters an invalid number, the program will just ignore it, and ask for another number. Only numbers 1-6 inclusive and 0 are valid.

Example output Enter a die roll or 0 to exit 6 Next die roll? 6 Next die roll? 7 Next die roll? 4 Next die roll? 0

[code].....

View 3 Replies View Related

C++ :: Fill Between Lines Of A Graph (koolplot)

Apr 16, 2014

I am using koolplot plot graph and able to plot two lines in a graph. My question is how to fill between the lines? Is it possible to do so with koolplot? or i should use another library?

View 2 Replies View Related

C++ :: Making Bar Graph By Comparing Two Vectors

Jan 5, 2014

I am trying to compare two vectors and make a bar graph. I have tried sorting it and pushing it into another vector but this issue is when I go to output it. My logic is wrong.

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <iomanip>

int main(int argc, const char * argv[]) {

[Code] ....

Output

22 *
44 *
22 *
45 *
33 *
44 *
18 *
34 *
33 *
12 *
3 *
5 *
34 *
33 *
5 *
7 *
22 *
44 *
49 *
9 *
18 *

View 3 Replies View Related

C++ :: Graph And Binary Tree Traversal

Mar 30, 2014

I used a BFS to simulate graph-join structure in a C++ code, and had a binary tree that asks the user e.g. to insert a node in the tree among other options, anyhow, I reached a point where I should pass a set of vertices from the graph to the tree, but how to do so. So I wanted to ask is such a thing possible? i.e. passing vertices from a graph to a tree automatically (no user involvement is needed)?

View 4 Replies View Related

C++ :: Adjacency List Graph Representation?

May 3, 2014

"My Programm is crashing and i dont know why?"

#include<iostream>
using namespace std;
int arr[3];
struct edges {
int edge_data;
edges *next;

[code]....

View 1 Replies View Related

C++ :: Complete Graph Data Structure

Apr 13, 2013

I need building a complete graph from a file. The format in the file is as follows.

[ vertex 1] [ x_coordinate 1] [ y_coordinate 1] [cityname 1]
[ vertex 2] [ x_coordinate 2] [ y_coordinate 2] [cityname 2]
. . .
[ vertex n] [ x_coordinate n] [ y_coordinate n] [cityname n]

What kind of data structure shall I use in order to store date in a complete graph so there is an edge between every pair?

View 7 Replies View Related

C++ :: Finding The Longest Path In A Graph

Dec 29, 2013

I was asked to find the longest path in a graph. I was thinking about using Dijsktra's algorithm after multiplying all the weights with -1 and run the program in normal way and find the shortest path. And then I'll multiply with -1 again and get the longest path. I think this should give me the longest path, do you think it would work? And also, I'm dealing with considerably big data, such as 1.000.000 nodes and many more edges. etc. and I have a time limit of 2 seconds and memory limit of 128mb. Any other data structure instead of Adjacency Matrix? Because I'm pretty sure it will exceed the limits.

View 2 Replies View Related

C++ :: Graph Class - How To Provide Virtual Iterators

May 29, 2013

I have a 'Graph' class, which has derived classes for Adjacency Matrix and Adjacency List representations.

How do I provide iterators for traversing vertices and edges, when the iterator classes would have different implementations for the different derived classes ?

The following way is the only one I can think of, but seems quite cumbersome.

Code:
class Base {
public:
class BaseIterator {

};
virtual const BaseIterator& begin();
virtual const BaseIterator& end();

[Code] .....

Or is there a pattern for doing this that I'm not aware of ? Would composition be a better idea here compared to polymorphism ? I mean, I can think like..a Graph can 'have' several representation 'objects' within it.

All the involved classes are templates,not sure if that makes the situation different.

View 7 Replies View Related

C :: Excel Graph - No Result When Try To Open File

Jan 14, 2015

Is not the first time I upload this program i know, but the problem now is that i try to export files, because i need to create an excel graph. But when I try to run it, I don't have any result, no file and no result of the program.

Code:

#include<stdio.h>#include <time.h>
#include <cstdlib>
#include <math.h>
int randfun(double arrX[], double arrY[], int size);
int cenfun(double arrX[], double arrY[], int size);
int rotatefun(double arrX[], double arrY[], int size, double center_x, double center_y, const double angle);

[Code] .....

View 2 Replies View Related

C :: Make A Live Price Chart Graph

Dec 14, 2013

The only language I know so far is C. Is there any way I can use c programming to display a live chart for a price graph including volume in different time intervals that I want to select. I want it to look like this URL....

View 2 Replies View Related

C++ :: Reading Tab-delimited File - Information Of A Graph

Jan 10, 2013

I have a network data file that looks like this:

2476
112
213
321
426
531
634
7312
843
945
...
...
...

The first row has two values - number of nodes (24) and number of links (76). Then it has all the link details (76 rows of data). I want to read this data. I have written out the following function:

First the structure definitions:

typedef struct {
int arcno;
int tail;
int head;
} arc_data;
typedef struct {
int forwardStarPoint;
int reverseStarPoint;

[Code] .....

The code is able to read the first line of data (i.e. it displays the numNodes and numArcs as 24 and 76). But then I get a lot of errors like this one

`Access violation writing location 0xCCCCCCD8`.

The program then crashes.

View 3 Replies View Related

C# :: How To Assign Distance Values To Fixed Graph

Apr 28, 2014

I'm working on a Dijkstra's algorithm with a fixed graph. My question is, how should I go about assign distance values to the graph. The user can start from any node.

View 4 Replies View Related

C Sharp :: How To Make Graph And Verify Its Properties

Apr 30, 2013

I want to make such application in which user make directed graphs along with relations between them. After that application show that which graph properties are proved in this graph e.g Reflexive, Irreflexive, Symmetric, Anti Symmetric, transitive etc

View 1 Replies View Related

C++ :: Utilizing Arrays Create Vertical Asterisk Graph?

Jun 25, 2013

This program needs to display a vertical graph of asterisks showing production for each plant in the company ...

Here is what I have so far:

***********************************
This program will read data and
display a vertical graph showing
productivity for each plant.
Reference Display 7.8 pg. 401-3
***********************************
*/
#include <iostream>

[Code].....

View 1 Replies View Related

C++ :: Represent Each Inputted Amount Of Rainfall Into A Graph With Loops?

Mar 15, 2013

I need to represent each inputted amount of rainfall into a graph like this.. how would I do this with loops?

View 5 Replies View Related

C++ :: Plot 3D Graph That Connects With Lines Some Points In 3D Space?

May 7, 2013

I would like a to plot a 3d graph that connects with lines some points in 3d space.

I have tried with qwt3d but the problem is that I cannot add labels to the points. Furthermore i didnt achieve to find a good guide for qwt3d and there are very few qwt3d examples on the web. library for C++ plotting that has those options(3d plot with adding labels in every point (node) option)?

View 3 Replies View Related

Visual C++ :: Implementing Real Time Graph To Application?

Nov 15, 2013

I was assigned a project to implement a real time graph to an application which continuously outputs data numerically through the GUI. The application that was created to do this is written in C.

I have to turn those numerical numbers into a graphical display that is periodically updated to appear as real time.

My adviser suggested using NTgraph [URL] ...... I had no clue how to implement this to my code and was finally able to understand that the .OCX needs to be registered as a COM and then imported to the application using visual studios. However, I get an error when I try importing it since it is in C (Visual Studios 8) and not an MFC application.

So my question is if it would be possible to implement the ActiveX control to my application even though it is not an MFC application and how to go about it.

View 6 Replies View Related







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