what's wrong with my code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what's wrong with my code?

i still don't know how can i use template in class. #include<iostream> using namespace std; template < typename E > class node { E elem; node < E > *next; friend class list < E >; }; template < typename E > class list { private: node < E > *head; public: list () { head = NULL; } ~list () { while (!empty ()) removefront (); } bool empty () { return (head == NULL); } const E & front () const { return head->elem; } void addfront (const E & n) { node < E > *v = new node < E >; v->elem = n; v->next = head; head = v; } void addend (const E & n) { node < E > *v = new node < E >; v->elem = n; v->next = NULL; node < E > *cur = head; while (cur != NULL) { cur = cur->next; } cur->next = v; } void insertionafter (E & x, const E & n) { node < E > *cur = head; while (cur->elem != x) { cur = cur->next; } node < E > *newnode = new node < E >; newnode->elem = n; node < E > *aftercur = new node < E >; aftercur = cur->next; cur->next = newnode; newnode->next = aftercur; delete aftercur; } void deletionafter (E & x) { node < E > *cur = head; while (cur->elem != x) { cur = cur->elem; } node < E > *aftercur = new node < E >; aftercur = cur->next; cur->next = aftercur->next; delete aftercur; } void removefront () { if (!empty ()) node < E > *old = new node < E >; old = head; head = old->next; delete old; } void reverse (node < E > *x, node < E

2nd Jun 2021, 7:10 AM
narges ghanbari
narges ghanbari - avatar
2 Answers
+ 3
Right now only thing I find problematic is code being incomplete. It's better to put the source code in code playground and share the link here if you are one mobile app, you can see the following for more info 👇 https://www.sololearn.com/post/75089/?ref=app
2nd Jun 2021, 7:19 AM
Arsenic
Arsenic - avatar
0
oof, every line has space. can't read it.
2nd Jun 2021, 8:58 AM
Rellot's screwdriver
Rellot's screwdriver - avatar