您的位置:首页 > 理论基础 > 数据结构算法

【数据结构_链表_List_0957】逆序输出链表

2017-03-06 21:16 344 查看
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
typedef struct node
{
char str;
struct node *next;
}List;
int main()
{
List *head,*p,*q,*temp;
head=(List *)malloc(sizeof(List));
int num;
while(cin>>num)
{
int i;
p=head;
for(i=0;i<num;i++)
{
q=(List *)malloc(sizeof(List));
cin>>q->str;
p->next=q;
p=q;
}
p->next=NULL;
temp=head;
temp=temp->next;
while(num>0)
{
i=0;
for(;i<num-1;i++)
{
temp=temp->next;
}cout<<temp->str<<" ";
temp=head->next;
num--;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据结构 链表