zoukankan      html  css  js  c++  java
  • 链表打印从尾到头打印链表

    在本文中,我们主要介绍链表打印的内容,自我感觉有个不错的建议和大家分享下

        

     

        

     

        每日一道理
    生命不是一篇"文摘",不接受平淡,只收藏精彩。她是一个完整的过程,是一个"连载",无论成功还是失败,她都不会在你背后留有空白;生命也不是一次彩排,走得不好还可以从头再来,她绝不给你第二次机会,走过去就无法回头。
    #include <stdlib.h> 
    #include <stdio.h> 
    #include <stack>
    #include <algorithm> 
    using namespace std;
    
    struct ListNode{
    	int m_Value;
    	ListNode *m_pNext;
    }*List;
    bool deleted =false;
    void AddNodeToTail(ListNode** pHead,int value){
    	ListNode* pNew = new ListNode();
    	pNew->m_Value = value;
    	pNew->m_pNext = NULL;
    	if (NULL== *pHead)
    	{
    		*pHead=pNew;
    	}
    	else{
    		ListNode* pNode=*pHead;
    		while(pNode->m_pNext!=NULL)
    			pNode= pNode->m_pNext;
    
    		pNode->m_pNext=pNew;
    	}
    }
    
    void PrintListFromTail(ListNode* pHead){
    	std::stack<int> nodes;
    	ListNode* pNode=pHead;
    	while(NULL!=pNode){
    		nodes.push(pNode->m_Value);
    		pNode=pNode->m_pNext;
    	}
    	printf("从尾到头打印链表:\n");
    	while(!nodes.empty()){
    		printf("%d",nodes.top());
    		nodes.pop();
    		if(!nodes.empty())
    			printf("->");
    	}
    }
    
    int main(void){
    	for (int i=0;i<20;i++)
    	{
    		AddNodeToTail(&List,i);
    	}
    	ListNode* p=List;
    	while(p!=NULL){
    		printf("%d",p->m_Value);
    		p = p->m_pNext;
    		if(p!=NULL)
    			printf("->");
    	}
    
    	printf("\n");
    	PrintListFromTail(List);
    
    	getchar();
    	return 0;
    }

        

     

    文章结束给大家分享下程序员的一些笑话语录: 很多所谓的牛人也不过如此,离开了你,微软还是微软,Google还是Google,苹果还是苹果,暴雪还是暴雪,而这些牛人离开了公司,自己什么都不是。

  • 相关阅读:
    Problem of saving images in WPF (RenderTargetBitmap)zz
    巴特沃斯(Butterworth)滤波器 (2)
    巴特沃斯(Butterworth)滤波器 (1)
    vs发布的程序不依赖运行时库msvcp100.dll
    [leetcode]Word Search @ Python
    [leetcode]Merge Sorted Array @ Python
    [leetcode]Set Matrix Zeroes @ Python
    [leetcode]Restore IP Addresses @ Python
    [leetcode]Interleaving String @ Python
    [leetcode]Distinct Subsequences @ Python
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3061710.html
Copyright © 2011-2022 走看看