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

Define bit fields, Define Bit Fields Bit Fields permits the packing of ...

Define Bit Fields Bit Fields permits the packing of data in a structure. This is particularly useful when memory or data storage is at a premium. Usual examples: Packing

Programming and solving problems, One person who is specialist at programmi...

One person who is specialist at programming and solving problems with a computer Project Description: Dear Potential computer, hardware, programming and software genius, I

Explain brief about class and objects, Question 1 Write a program that acc...

Question 1 Write a program that accepts a 3x3 matrix from the user and finds the transpose of it Question 2 Explain Brief about class and objects. Also describe friend functi

Caesar cipher, This task involves char arrays and pointer based string hand...

This task involves char arrays and pointer based string handling. Which we use to make a simple encryption program, using a Caesar Cipher, Write a program that: a. Asks

Convert coordinate - c++ program, Convert coordinate: class rect{  ...

Convert coordinate: class rect{                 private :                 float  x,y;                   public :                 void  input()

#coding, Smugglers are becoming very smart day by day. Now they have develo...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

Basic concepts, what is the diffeerence between c and c++

what is the diffeerence between c and c++

How can i present printing for my class fred?, A: Use operator overloading ...

A: Use operator overloading to present a friend left-shift operator, operator #include class Fred { public: friend std::ostream& operator ... private: int i_; // onl

Program, Define a class polynomial with three private data members a, b and...

Define a class polynomial with three private data members a, b and c of type double to represent the coefficient of two degree polynomial(ax^2+bx+c). Include a constructor in a pol

Msp, A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of t

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