Program for queue and vector, C/C++ Programming

Assignment Help:

#include

#include

#include

using namespace std;

#define MAX 5

#define INF (1<<20)

#define DEBUG if(0)

#define pii pair< int, int >

#define pb(x) push_back(x)

class Node

{

int id:

int p[1][2];

class Node *next[5];

 bool operator() (const pii &a, const pii &b)

{

        return a.second > b.second;

 } ;

priority_queue< pii, vector< pii >, Node > Q;

vector< pii > G[MAX];

int D[MAX];

bool F[MAX];

int main()

{

int i, u, v, w, sz, nodes, edges, starting;

// create graph

cin >> nodes >> edges;

for(i=0; i

{

cin>> u >> v >> w;

G[u].pb(pii(v, w));

G[v].pb(pii(u, w)); // for undirected

}

cin >> starting;

for(i=1; i<=nodes; i++) D[i] = INF;

D[starting] = 0;

Q.push(pii(starting, 0));

while(!Q.empty())

{

   u = Q.top().first;

   Q.pop();

   if(F[u]) continue;

  sz = G[u].size();

  DEBUG cout<<"visiting from "<< u;

  for(i=0; i

{

        v = G[u][i].first;

         w = G[u][i].second;

         if(!F[v] && D[u]+w < D[v])

                {

                 DEBUG cout<<  v;

                 D[v] = D[u] + w;

                 Q.push(pii(v, D[v]));

                 }

         }

DEBUG cout << "\n";

F[u] = 1;

}

for(i=1; i<=nodes; i++)

cout << "Node"<< i<< "min weight"<<  D[i]);

return 0;

}


Related Discussions:- Program for queue and vector

Stack, flow chart for push operation in stack

flow chart for push operation in stack

Explain logical operators, Logical Operators We say any expression that...

Logical Operators We say any expression that evaluates to zero is a FALSE logic condition and that evaluating to non-zero value is a TRUE condition. Logical operators are usefu

Flowchart, create a flowchart that display the assume that there are 3 sect...

create a flowchart that display the assume that there are 3 section each student ?

Stack, write a simple c++ program to implement a stack: 1. push 2. pop

write a simple c++ program to implement a stack: 1. push 2. pop

Define variable declaration in c++, Variable Declaration This declarati...

Variable Declaration This declaration of variables in the C language is permitted only in the starting of their block, prior to executable program statements. In C++ declaratio

Bouncing Ball, Create an applet that bounces a blue ball inside an applet u...

Create an applet that bounces a blue ball inside an applet using Thread. The ball (diameter is 10) will start at position (0,0). When the ball hits the edge of the applet, the ba

Explain passing and returning objects, Passing and Returning Objects Ob...

Passing and Returning Objects Objects can be passed to a function and returned back just like normal variables. When an object is passed by content, the compiler makes another

Vogels approximation transportation problem, Vogels approximation transport...

Vogels approximation transportation problem in c language source code

Project, Project Overview A certain financial institution (bank) wishes to ...

Project Overview A certain financial institution (bank) wishes to promote its new business products/services by conducting road shows in rural areas. Their aim is to encourage peop

Oops, write a c++ program to find the prime numbers

write a c++ program to find the prime numbers

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd