#include <iostream>#include <stack>using namespace STD;Template<TypeNameType>structnode{Type data; Node *next; Node (Type D = Type ()):d ATA (d), next (NULL) {}};Template<TypeNameType>classlist{ Public: List () {head = NULL; }voidInsert (Type a[],intN) { for(intI=0; i<n;i++) {_insert (head,a[i]); } }voidPrintf ()//sequential printing.{node<type> *p = head; while(P!=null) {cout<<p->data<<"\ T"; p = p->next; }cout<<endl; }voidPrintf_a ()//Recursive reverse print node.{_printf_a (head); }voidPrintf_b () {_printf_b (head);//stack for reverse print nodes. }Private:void_printf_b (node<type> *t) {node<type> *p = t; Stack<Node<Type>*> St; while(P!=null) {St.push (P); p = p->next; } while(St.empty ()! =true) {p = st.top (); St.pop ();cout<<p->data<<"\ T"; }cout<<endl; }BOOL_printf_a (node<type> *t) {if(T!=null) {_printf_a (T->next);cout<<t->data<<"\ T"; } }BOOL_insert (node<type> *t,type val) {node<type> *p = t; Node<type> *s =NewNode<type> (Val);if(T==null) {head = s; }Else{ while(p->next!=null) p=p->next; P->next = s; } }Private: Node<type> *head;};intMain () {inta[]={1,2,3,4,5,6,7,8}; list<int>List;List. Insert (A,8);//list. Printf_a (); //list. Printf (); List. Printf_b ();return 0;}
C + + linked list Reverse print node