本帖最后由 独一无② 于 2016-1-26 14:36 编辑
将一数据链表中数据 小于零的数都 转移到 正数前面
如 输入 -x -x x x -x x
输出-x -x -x x x x
如何转移 这部分想不出来,只会创建这部分
# include <stdio.h>
# include <stdlib.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node *head,*p,*q,*t;
int i,j,k;
char str[50];
head=NULL;
scanf("%d",&j);
while(j--)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&i);
p->data=i;
p->next=NULL;
if(head == NULL)
head=p;
else
q->next=p;
q=p;
}
// 这里转移不会
t=head;
while(t != NULL)
{
printf("%d ",t->data);
t=t->next;
}
}
求思路,大神帮帮忙 |