bb[i]=bb[i+1];
后面用个goto到前面,因为112233输入2后 变为11233 这个时候计数器已经指向了第一个3。给你个我以前写的链表程序,也不是很好,但能解决你的问题。
#include <stdlib.h>
#define null 0
struct list
{int data;
struct list *next;
};
main()
{struct list *head,*p,*q,*r;
int n=0,m,flag=0;
char a;
clrscr();
p=q=(struct list *)malloc(sizeof(struct list));
printf("please input a data:");
scanf("%d",&p->data);
head=null;
while(p->data!=0)
{n=n+1;
if(n==1)
head=p;
else
q->next=p;
q=p;
p=(struct list *)malloc(sizeof(struct list));
printf("please input a number:");
scanf("%d",&p->data);
}
q->next=null;
p=head;
do
{printf("%d\t",p->data);
p=p->next;
}while(p!=null);
{printf("while data?");
scanf("%d",&m);
l:p=head;
if(head==null)
printf("error!\n");
else
while(m!=p->data&&p->next!=null)
{q=p;
p=p->next;
}
if(m==(p->data))
{if(p==head)
head=p->next;
else
q->next=p->next;
goto l;
}
p=head;
do
{printf("%d\t",p->data);
p=p->next;
}
while(p!=null);
}
printf("\n");
后面用个goto到前面,因为112233输入2后 变为11233 这个时候计数器已经指向了第一个3。给你个我以前写的链表程序,也不是很好,但能解决你的问题。
#include <stdlib.h>
#define null 0
struct list
{int data;
struct list *next;
};
main()
{struct list *head,*p,*q,*r;
int n=0,m,flag=0;
char a;
clrscr();
p=q=(struct list *)malloc(sizeof(struct list));
printf("please input a data:");
scanf("%d",&p->data);
head=null;
while(p->data!=0)
{n=n+1;
if(n==1)
head=p;
else
q->next=p;
q=p;
p=(struct list *)malloc(sizeof(struct list));
printf("please input a number:");
scanf("%d",&p->data);
}
q->next=null;
p=head;
do
{printf("%d\t",p->data);
p=p->next;
}while(p!=null);
{printf("while data?");
scanf("%d",&m);
l:p=head;
if(head==null)
printf("error!\n");
else
while(m!=p->data&&p->next!=null)
{q=p;
p=p->next;
}
if(m==(p->data))
{if(p==head)
head=p->next;
else
q->next=p->next;
goto l;
}
p=head;
do
{printf("%d\t",p->data);
p=p->next;
}
while(p!=null);
}
printf("\n");