Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<cmath>
- using namespace std;
- struct graph
- {
- int x;
- int y;
- double weight;
- };
- struct node
- {
- graph G;
- node* next;
- };
- void push (node* &p, graph G)
- {
- node *temp;
- temp = new node;
- temp->G = G;
- temp->next =p;
- p= temp;
- }
- void show (node* &p)
- {
- while (p)
- {
- cout<<p->G.x <<" "<< p->G.y << " "<<p->G.weight<<endl;
- p = p->next;
- }
- }
- void read (node* &p,ifstream &file)
- {
- p = NULL;
- graph g;
- while (file >> g.x >>g.y >> g.weight)
- {
- push(p, g);
- }
- }
- void write (node* p,ofstream &out)
- {
- while (p)
- {
- out<<p->G.x <<" "<< p->G.y << " "<<p->G.weight<<endl;
- p = p->next;
- }
- }
- bool IJustSpentACheck (node* &p,int x,int y)
- {
- while (p)
- {
- if ((p ->G.x == x && p->G.y == y)||(p ->G.x == y && p->G.y == x ))
- {
- if (p->G.weight > 0 )
- return true;
- }
- p=p->next;
- }
- return false;
- }
- int main()
- {
- node *list;
- ifstream f ("input.txt");
- ofstream out ("output.txt");
- read(list, f);
- write(list, out);
- int x,y;
- cout<<"Enter x: ";
- cin>>x;
- cout<<"Enter y: ";
- cin>>y;
- if (IJustSpentACheck(list, x, y))
- cout<<"Yes";
- else
- cout<<"No";
- }
Add Comment
Please, Sign In to add comment