RT就是要刪除偶數,接下來是我的程式: #include<stdio.h> #include<stdlib.h> #include<string.h> struct stud_node{ int num; struct stud_node *next; }; int main(void) { struct stud_node *head,*tail, *p,*ptr1,*ptr2; int num; int siz... RT就是要刪除偶數,接下來是我的程式:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stud_node{
int num;
struct stud_node *next;
};
int main(void)
{
struct stud_node *head,*tail, *p,*ptr1,*ptr2;
int size = sizeof(struct stud_node);
head = tail = NULL;
scanf("%d", &num);
while(num != 0){
p = (struct stud_node *)malloc(size);
p->num = num;
p->next = NULL;
if(head==NULL)
head=p;
else
tail->next = p;
tail = p;
}
//以上為輸入
ptr1=head;
ptr2=head->next;
while(ptr2!=NULL){
if((ptr2->num)%2==0){
ptr1->next=ptr2->next;
free(ptr2);
ptr1=ptr2;
ptr2=ptr1->next;
for(p = head; p != NULL; p = p->next)
printf("%d", p->num);
printf(" ");
return 0;
RT就是要刪除偶數,接下來是我的程式: #include<stdio.h> #include<stdlib.h> #include<string.h> struct stud_node{ int num; struct stud_node *next; }; int main(void) { struct stud_node *head,*tail, *p,*ptr1,*ptr2; int num; int siz... RT就是要刪除偶數,接下來是我的程式:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stud_node{
int num;
struct stud_node *next;
};
int main(void)
{
struct stud_node *head,*tail, *p,*ptr1,*ptr2;
int num;
int size = sizeof(struct stud_node);
head = tail = NULL;
scanf("%d", &num);
while(num != 0){
p = (struct stud_node *)malloc(size);
p->num = num;
p->next = NULL;
if(head==NULL)
head=p;
else
tail->next = p;
tail = p;
scanf("%d", &num);
}
//以上為輸入
ptr1=head;
ptr2=head->next;
while(ptr2!=NULL){
if((ptr2->num)%2==0){
ptr1->next=ptr2->next;
free(ptr2);
}
else
ptr1=ptr2;
ptr2=ptr1->next;
}
for(p = head; p != NULL; p = p->next)
{
printf("%d", p->num);
printf(" ");
}
return 0;
}