单链表的就地逆置

来源:互联网 发布:淘宝网购物女装衬衫 编辑:程序博客网 时间:2024/06/07 09:46
#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;typedef struct Node{    int data;    struct Node *next;}LNode;void Creat_LinkList(LNode **head,int n){    LNode *p;    int x;    (*head) = (LNode*)malloc(sizeof(LNode));    //(*head)->data = x;    (*head)->next = NULL;    while(n--)    {        scanf("%d",&x);        p = (LNode*)malloc(sizeof(LNode));        p->data = x;        p->next = (*head)->next;        (*head)->next = p;    }}void print(LNode *h){    LNode *p;    p=h->next;    while(p!=NULL)    {        printf("%d\n",p->data);        p=p->next;    }}int main(){    LNode *s;    int n;    scanf("%d",&n);    Creat_LinkList(&s,n);    print(s);    return 0;}
0 0
原创粉丝点击