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 x1,x2;
- int y1,y2;
- 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.x1 <<" "<< p->G.y1 <<" "<< p->G.x2<<" " << p->G.y2 << " "<<p->G.weight<<endl;
- p = p->next;
- }
- }
- void read (node* &p,ifstream &file)
- {
- p = NULL;
- graph G;
- while (file >> G.x1 >>G.y1 >> G.y2 >>G.x2)
- {
- G.weight = sqrt((pow(G.x1 - G.x2, 2)+pow(G.y1 - G.y2,2)));
- push(p, G);
- }
- }
- void write (node* &p,ofstream &out)
- {
- while (p)
- {
- out<<p->G.x1 <<" "<< p->G.y1 <<" "<< p->G.x2<<" " << p->G.y2 << " "<<p->G.weight<<endl;
- p = p->next;
- }
- }
- int main()
- {
- node *list;
- ifstream f ("input.txt");
- ofstream out ("output.txt");
- read(list, f);
- write(list, out);
- }
Add Comment
Please, Sign In to add comment