Advertisement
GerexD

beszur ele, utan

May 14th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream f("szamok.txt");
  7.  
  8. struct elem
  9. {
  10. int inf;
  11. elem *kov;
  12. };
  13. elem *elso=NULL;
  14.  
  15. elem* feltolt(elem *elso)
  16. {
  17. int x;
  18.  
  19. elem *uj, *utolso=NULL;
  20. while(f>>x)
  21. {
  22. uj=new elem;
  23. uj->inf=x;uj->kov=NULL;
  24. if(utolso!=NULL) utolso->kov=uj;
  25. utolso=uj;
  26. if(elso==NULL) elso=uj;
  27. }
  28. return elso;
  29. }
  30. ///adott x utan beszurjuk y-t
  31. elem* beszur_utan(elem* elso, int x, int y)
  32. {
  33. ///megkeressuk x cimet
  34. elem* p=elso;
  35. while(p!=NULL && p->inf!=x) p=p->kov;
  36. elem* uj=new elem;
  37. uj->inf=y;
  38. uj->kov=p->kov;
  39. p->kov=uj;
  40.  
  41. }
  42.  
  43. elem* beszur_ele(elem* elso, int x, int m)
  44. {
  45. elem* p=elso;
  46. elem* uj;
  47. ///megkeressuk az adott elem(x) elotti cimet
  48. while(p->kov->inf!=x) p=p->kov;
  49. uj=new elem;
  50. uj->inf=m;
  51. uj->kov=p->kov;
  52. p->kov=uj;
  53.  
  54. }
  55.  
  56. void kiir(elem *elso)
  57. {
  58. while(elso!=NULL)
  59. {
  60. cout<<elso->inf<<" ";
  61. elso=elso->kov; }
  62. }
  63. int main()
  64. {
  65. elso=feltolt(elso);
  66. kiir(elso);
  67. cout<<endl;
  68. beszur_utan(elso,23,100);
  69. kiir(elso);
  70. cout<<endl;
  71. beszur_ele(elso,45,200);
  72. kiir(elso);
  73.  
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement