数字,字符串的从尾到头的输出

一 链表的从尾到头输出

#include "stdio.h"
#include "malloc.h"

struct ListNode  
{  
      int       m_nKey;  
      ListNode* m_pNext;  
}; 

///   
// Print a list from end to beginning   
// Input: pListHead - the head of list   
///   
void PrintListReversely(ListNode* pListHead)  
{  
      if(pListHead != NULL)  
      {  
            // Print the next node first   
           // if (pListHead->m_pNext != NULL)  
           // {  
                  PrintListReversely(pListHead->m_pNext);  
           // }  
   
            // Print this node   
            printf("%3d", pListHead->m_nKey);  
      }
	  
}  
int main()
{
	struct ListNode * head,*p1,*p2,*p3;
	head = NULL;
	p1 = (struct ListNode *)malloc(sizeof(struct ListNode ));
	p2 = (struct ListNode *)malloc(sizeof(struct ListNode ));
	p3 = (struct ListNode *)malloc(sizeof(struct ListNode ));

	p1->m_nKey = 1;
	p2->m_nKey = 2;
	p3->m_nKey = 3;

	p1->m_pNext = p2;
	p2->m_pNext = p3;
	p3->m_pNext = NULL;

	head = p1;

	PrintListReversely(head);

	printf("\n");

	return 0;

}

二 字符串的从尾到头输出

#include "stdio.h"

void printListReverse(char *p)
{
	if(*p != '\0')
	{
		printListReverse(p+1);
		printf("%2c",*p);		
	}
}

void main()
{
	char *string = "1234567";

	printListReverse(string);

	printf("\n");
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值