Advertisement
Guest User

lsvhlsifgvhls

a guest
Oct 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cctype>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6. typedef struct nod
  7. {
  8. int l,c,x;
  9. struct nod*ant,*urm;
  10. }NOD;
  11. NOD *p1,*u1;
  12. FILE *f=fopen("date.in","r");
  13. FILE *g=fopen("date.in","w");
  14. NOD *caut(NOD *p,NOD *u,int l,int c)
  15. {
  16. NOD*q;
  17. p=q;
  18. while(q!=NULL)
  19. {
  20. if(q->l==l && q->c==c)
  21. return NULL;
  22. if(q->l>l)
  23. return q;
  24. if(q->l==l && q->c>c)
  25. return q;
  26. q=q->urm;
  27.  
  28. }
  29. }
  30. void adaug(NOD *&p,NOD *&u,int l,int c,int x)
  31. {
  32. NOD *q,*r;
  33. r=(NOD*)malloc(sizeof(NOD));
  34. r->ant=r->urm=NULL;
  35. r->l=l;
  36. r->c=c;
  37. r->x=x;
  38. if(p==NULL)
  39. p=u=r;
  40. else if((r->l<p->l) || r->l==p->l && r->c<p->c)
  41. {
  42. u->urm=p;
  43. r->ant=r;
  44. p=r;
  45. }
  46. else if(r->l>u->l || r->l==u->l && r->c>u->c)
  47. {
  48. u->urm=r;
  49. r->ant=u;
  50. u=r;
  51.  
  52. }
  53. else
  54. {
  55. q=caut(p,u,l,c);
  56. if(q==NULL)
  57. free(r);
  58.  
  59. else
  60. {
  61. r->urm=q;
  62. r->ant=q->ant;
  63. q->ant->urm=r;
  64. q->ant=r;
  65.  
  66. }
  67. }
  68. }
  69. void creare(NOD*&p,NOD*&u,int n)
  70. {
  71. int x,y,z,i,m;
  72. fscanf(f,"%d%d",&n,&m);
  73. for(i=1;i<=m;i++)
  74. {
  75. fscanf(f,"%d%d%d",&x,&y,&z);
  76. adaug(p,u,x,y,z);
  77. }
  78.  
  79. }
  80. void afis_mat(NOD *p,NOD *u,int n)
  81. {
  82. NOD *q;
  83. q=p;
  84. int i,j,OK;
  85. for(i=1;i<=n;i++)
  86. {
  87. for(j=1;j<=n;j++)
  88. {
  89. q=p;
  90. OK=0;
  91. while(q!=NULL)
  92. if(i==q->l && j==q->c)
  93. {
  94. printf("%4d",q->x);
  95. OK=1;
  96. break;
  97.  
  98. }
  99. q=q->urm;
  100. }
  101. if(OK==0)
  102. printf("%4d",0);
  103. printf("\n");
  104. }
  105. }
  106.  
  107.  
  108. int main()
  109. {
  110. int n;
  111. creare(p1,u1,n);
  112. afis_mat(p1,u1,n);
  113.  
  114.  
  115.  
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement