Click here to Skip to main content
15,888,461 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionC++ Smartphone application, get data from MySQL Pin
PonSvens29-May-16 10:04
PonSvens29-May-16 10:04 
AnswerRe: C++ Smartphone application, get data from MySQL Pin
CPallini29-May-16 20:58
mveCPallini29-May-16 20:58 
AnswerRe: C++ Smartphone application, get data from MySQL Pin
leon de boer29-May-16 22:53
leon de boer29-May-16 22:53 
AnswerRe: C++ Smartphone application, get data from MySQL Pin
Richard MacCutchan30-May-16 1:16
mveRichard MacCutchan30-May-16 1:16 
GeneralRe: C++ Smartphone application, get data from MySQL Pin
leon de boer30-May-16 2:43
leon de boer30-May-16 2:43 
GeneralRe: C++ Smartphone application, get data from MySQL Pin
Richard MacCutchan30-May-16 3:02
mveRichard MacCutchan30-May-16 3:02 
GeneralRe: C++ Smartphone application, get data from MySQL Pin
David Crow30-May-16 5:04
David Crow30-May-16 5:04 
Question8Puzzle game Pin
Abdulrahman Mostafa24-May-16 16:31
Abdulrahman Mostafa24-May-16 16:31 
I have been trying to create a puzzle that can solve itself using BFS algorithm. Currently, the search algorithm and the main but I don't know how to integrate both of them together.

my BFS:
C#
#ifndef BFS_h
#define BFS_h
// Program to print BFS traversal from a given source vertex. BFS(int s)
// traverses vertices reachable from s.
#include<iostream>
#include <list>

using namespace std;

// This class represents a directed graph using adjacency list representation
class Graph
{
    int V;    // No. of vertices
    list<int> *adj;    // Pointer to an array containing adjacency lists
public:
    Graph(int V);  // Constructor
    void addEdge(int v, int w); // function to add an edge to graph
    void BFS(int s);  // prints BFS traversal from a given source s
};

Graph::Graph(int V)
{
    this->V = V;
    adj = new list<int>[V];
}

void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w); // Add w to v’s list.
}

void Graph::BFS(int s)
{
    // Mark all the vertices as not visited
    bool *visited = new bool[V];
    for(int i = 0; i < V; i++)
        visited[i] = false;
    
    // Create a queue for BFS
    list<int> queue;
    
    // Mark the current node as visited and enqueue it
    visited[s] = true;
    queue.push_back(s);
    
    // 'i' will be used to get all adjacent vertices of a vertex
    list<int>::iterator i;
    
    while(!queue.empty())
    {
        // Dequeue a vertex from queue and print it
        s = queue.front();
        cout << s << " ";
        queue.pop_front();
        
        // Get all adjacent vertices of the dequeued vertex s
        // If a adjacent has not been visited, then mark it visited
        // and enqueue it
        for(i = adj[s].begin(); i != adj[s].end(); ++i)
        {
            if(!visited[*i])
            {
                visited[*i] = true;
                queue.push_back(*i);
            }
        }
    }
}



and my main:
C++
#include "queue"
#include <iostream>
#include <iomanip>
#include "BFS.h"
#include "A*search.h"

using namespace std;

int main()
{
    int s;
    int box1=3,box2=6,box3=9,box4=1,box5=s,box6=7,box7=5,box8=8,box9=2;
    
    cout << " -----------" << endl;
    cout << " | " << box1 << " | " << box2 << " | " << box3 << " | " << endl;
    cout << " -----------" << endl;
    cout << " | " << box4 << " | " << box5 << " | " << box6 << " | " << endl;
    cout << " -----------" << endl;
    cout << " | " << box7 << " | " << box8 << " | " << box9 << " | " << endl;
    cout << " -----------" << endl;
    
    
    
       void BFS(int s);
    
       
    
    
    
    
    return 0;

AnswerRe: 8Puzzle game Pin
Richard MacCutchan24-May-16 21:56
mveRichard MacCutchan24-May-16 21:56 
QuestionRe: 8Puzzle game Pin
David Crow25-May-16 4:34
David Crow25-May-16 4:34 
QuestionEdit Subitems In Owner Drawn List Pin
DanYELL23-May-16 4:58
DanYELL23-May-16 4:58 
QuestionRe: Edit Subitems In Owner Drawn List Pin
Richard MacCutchan23-May-16 5:39
mveRichard MacCutchan23-May-16 5:39 
AnswerRe: Edit Subitems In Owner Drawn List Pin
DanYELL23-May-16 5:50
DanYELL23-May-16 5:50 
GeneralRe: Edit Subitems In Owner Drawn List Pin
leon de boer23-May-16 6:02
leon de boer23-May-16 6:02 
GeneralRe: Edit Subitems In Owner Drawn List Pin
Richard MacCutchan23-May-16 6:08
mveRichard MacCutchan23-May-16 6:08 
AnswerRe: Edit Subitems In Owner Drawn List Pin
leon de boer23-May-16 5:59
leon de boer23-May-16 5:59 
AnswerRe: Edit Subitems In Owner Drawn List Pin
Bram van Kampen1-Jun-16 16:09
Bram van Kampen1-Jun-16 16:09 
QuestionHow to send huge data via sockets in continuous intervals Pin
manoharbalu22-May-16 19:09
manoharbalu22-May-16 19:09 
AnswerRe: How to send huge data via sockets in continuous intervals Pin
Richard MacCutchan22-May-16 20:58
mveRichard MacCutchan22-May-16 20:58 
GeneralRe: How to send huge data via sockets in continuous intervals Pin
manoharbalu23-May-16 3:08
manoharbalu23-May-16 3:08 
GeneralRe: How to send huge data via sockets in continuous intervals Pin
Richard MacCutchan23-May-16 3:33
mveRichard MacCutchan23-May-16 3:33 
AnswerRe: How to send huge data via sockets in continuous intervals Pin
leon de boer22-May-16 22:16
leon de boer22-May-16 22:16 
GeneralRe: How to send huge data via sockets in continuous intervals Pin
manoharbalu23-May-16 3:07
manoharbalu23-May-16 3:07 
GeneralRe: How to send huge data via sockets in continuous intervals Pin
leon de boer23-May-16 5:41
leon de boer23-May-16 5:41 
GeneralRe: How to send huge data via sockets in continuous intervals Pin
manoharbalu24-May-16 1:57
manoharbalu24-May-16 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.