/*title: (1) First write a single-linked list (2) to the chain list direction output problem-solving ideas: (a) The use of stack, LIFO strategy. (b) Recursion*/#include<stdio.h>#include<stdlib.h>#include<stack>#include<iostream>using namespaceStd;typedefstructlistnode{intM_nvalue; structListNode *M_pnext;} Lnode;voidListaddnode (Lnode *head) {Lnode*p = head, *p_inter =NULL; if(! (P_inter = ((Lnode *)malloc(sizeof(Lnode))))) {printf ("The memery is don ' t create it\n"); return; } p_inter->m_pnext =NULL; intdata; printf ("Please enter a number: \ n"); scanf_s ("%d", &data); P_inter->m_nvalue =data; while(P->m_pnext! =NULL) {P= p->M_pnext; } P->m_pnext =P_inter;} Lnode* CreateList (Lnode *head) { if(! (head = ((Lnode *)malloc(sizeof(Lnode))))) {printf ("The memery is don ' t create it\n"); returnNULL; } head->m_pnext =NULL; intdata; printf ("Please enter a number: \ n"); scanf_s ("%d", &data); Head->m_nvalue =data; Lnode*p = head, *p_inter =NULL; CharX_cin ='Y'; while(true) {printf ("do you want to continue adding: n/n \ n"); CIN>>x_cin; if(X_cin = ='y'|| X_cin = ='Y') { ; } Else if(X_cin = ='N'|| X_cin = ='N') { returnHead; } Else { ; } listaddnode (P); }}voidShowlist (Lnode *head) { if(NULL = =head) {cout<<"list is empty \ n"<<Endl; return; } Lnode*p =Head; while(P! =NULL) {printf ("%d\n", p->m_nvalue); P= p->M_pnext; }}voidReverseput (Lnode *Point ) {Stack<int>Stack_rev; Lnode*p =Point ; while(P! =NULL) {Stack_rev.push (P-m_nvalue); P= p->M_pnext; } while(!Stack_rev.empty ()) {cout<< stack_rev.top () <<Endl; Stack_rev.pop (); }}intMain () {Lnode*head =NULL; Head=CreateList (head); Showlist (head); Reverseput (head); return 0;}
5--Linked list Output