倒置2.c

来自「有关数据结构的一些例子。用C语言编写的。非常有价值的程序。对初学者有指导借鉴意义」· C语言 代码 · 共 59 行

C
59
字号
#define NULL 0
#include "stdio.h"
#include "stdlib.h"
typedef int datatype;

typedef struct node
{ datatype data;
  struct node *next;
} linklist;
linklist *head,*p,*q;
int i;

linklist *CREAT()
{ int ch;
  linklist *s,*r;
  head=(struct node*)malloc(sizeof(linklist));
  r=head;
  printf("链表:\n");
  scanf("%d",&ch);
  while(ch!=NULL)
  { s=(struct node*)malloc(sizeof(linklist));
    s->data=ch;
    r->next=s;
    r=s;
    printf("%d\t",s->data);
    scanf("%d",&ch);
  }
  r->next=NULL;
  return (head);
}

void INVERT(linklist *s)
{ linklist *a,*b,*c;
  a=s;
  b=a->next;
  while(b!=NULL)
  { c=b->next;
    b->next=a;
	a=b;
	b=c;
  }
  s->next=NULL;
  s=a;
  printf("倒置后的链表为:\n");
  while(s->next!=NULL)
  { printf("%d\t",s->data);
    s=s->next;
  }
}

int main(int argc, char* argv[])
{
	p=CREAT();
	printf("\n");
	INVERT(head);
    printf("\n");
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?