题解 | #句子逆序#

句子逆序

http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3

#include <stdio.h> 
#include <string.h>

/*typedef struct Student
    {int a;
    }Stu;
这里的Stu实际上就是struct Student的别名。Stu==struct Student
声明变量的时候就可:Stu stu1  或者 struct Student stu1
也可不写Student  只用 Stu stu1
*/
typedef struct  wordline
{
    char word[1000];
    struct  wordline *next;
    struct  wordline *prior;   
}wordline;
//循环双链表尾插法存储后逆序输出
int main() { 

    wordline* h;
    wordline* t;
    wordline* p;
    h= (wordline*)malloc(sizeof(wordline));
    h->next = h;
    h->prior =h;
    t = h;
    char str[1000];
    int num=0;
    while(scanf("%s",str)!=EOF){
     p= (wordline*)malloc(sizeof(wordline));
        strcpy(p->word, str);
        p->prior = t;
        p->next = h;
        t ->next = p;
        h->prior = p;
        t = p;
   }
   
   wordline* k;
   k = t;
   while(k!=h){
        printf("%s ",k->word);
       k = k->prior;
   }

   
  
return 0; 
}

全部评论

相关推荐

04-18 21:21
佛山大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务