fork download
  1. #include <iostream>
  2. using namespace std;
  3. struct node{
  4. int data;
  5. node* next;
  6. };
  7. class linked_l{
  8. private:
  9. node *head,*tail;
  10. public:
  11. linked_l(){
  12. head=NULL;
  13. tail=NULL;
  14. }
  15. void add_n(int n){
  16. node *temp=new node;
  17. temp->data=n;
  18. temp->next=NULL;
  19. if(head==NULL){
  20. head=temp;
  21. tail=temp;
  22. }
  23. else{
  24. tail->next=temp;
  25. tail=tail->next;
  26. }
  27.  
  28. }
  29. void add_front(int d){
  30. node *temp1=new node;
  31. temp1->data=d;
  32. temp1->next=NULL;
  33. if(head==NULL){
  34. head=temp1;
  35. tail=temp1;
  36. }
  37. else{
  38. temp1->next=head;
  39. head=temp1;
  40. }
  41. }
  42. void add_middle(node* pre,int g){
  43.  
  44. node *temp2=new node;
  45. temp2->data=g;
  46. temp2->next=pre->next;
  47. pre->next=temp2;
  48. }
  49. node* gethead()
  50. {
  51. return head;
  52. }
  53. void display()
  54. {
  55. node* temp;
  56. temp=head;
  57. while(temp!=NULL)
  58. {
  59. cout<<temp->data;
  60. temp=temp->next;
  61. }
  62. }
  63.  
  64. };
  65. int main()
  66. {
  67. linked_l a;
  68.  
  69. a.add_n(1);
  70. a.add_n(2);
  71. a.add_n(3);
  72. a.add_front(4);
  73. //a.add_middle(temp1,6);
  74. a.add_middle(a.gethead()->next);
  75. a.display();
  76. return 0;
  77. }
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:74:32: error: no matching function for call to ‘linked_l::add_middle(node*&)’
  a.add_middle(a.gethead()->next);
                                ^
prog.cpp:42:8: note: candidate: void linked_l::add_middle(node*, int)
   void add_middle(node* pre,int g){
        ^~~~~~~~~~
prog.cpp:42:8: note:   candidate expects 2 arguments, 1 provided
stdout
Standard output is empty