Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- */
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- ifstream fin("date.in");
- struct nod
- {
- int nr;
- nod *next;
- } *l[20];
- int n,m, t[2][20],start[20],k;
- void citire()
- {
- fin>>n>>m;
- int x,y;
- while(fin>>x>>y)
- {
- k++;
- t[0][k]=y;
- t[1][k]=start[x];
- start[x]=k;
- k++;
- t[0][k]=x;
- t[1][k]=start[y];
- start[y]=k;
- }
- }
- void construire()
- {
- nod *p;
- for(int i=1;i<=n;i++)
- {
- int x=start[i];
- while(x)
- {
- p=new nod;
- p->nr=t[0][x];
- p->next=l[i];
- l[i]=p;
- x=t[1][x];
- }
- }
- }
- void afisare()
- {
- /* for(int i=1;i<=n;i++)
- {
- int x=start[i];
- cout<<"\nLista nodului "<<i<<" : ";
- while(x)
- {
- cout<<t[0][x]<<" ";
- x=t[1][x];
- }
- cout<<endl;
- }
- */
- for(int i=1;i<=n;i++)
- {
- nod *x;
- x=l[i];
- cout<<"\nLista nodului "<<i<<" : ";
- while(x)
- {
- cout<<x->nr<<" ";
- x=x->next;
- }
- }
- }
- int main()
- {
- citire();
- construire();
- afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement