实验11-2-4 删除单链表偶数节点 (20 分)
Posted JamesGordan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实验11-2-4 删除单链表偶数节点 (20 分)相关的知识,希望对你有一定的参考价值。
#include <stdio.h> #include <stdlib.h> struct ListNode int data; struct ListNode *next; ; struct ListNode *createlist(); struct ListNode *deleteeven(struct ListNode *head); void printlist(struct ListNode *head) struct ListNode *p = head; while (p) printf("%d ", p->data); p = p->next; printf("\\n"); int main() struct ListNode *head; head = createlist(); head = deleteeven(head); printlist(head); system("pause"); return 0; /* 你的代码将被嵌在这里 */ struct ListNode *createlist() struct ListNode *head = NULL, *tail = NULL, *p; int num; scanf("%d", &num); while (num != -1) p = (struct ListNode*)malloc(sizeof(struct ListNode)); p->data = num; if (head == NULL) head = tail = p; else tail->next = p; tail = p; scanf("%d", &num); tail->next = NULL; return head; struct ListNode *deleteeven(struct ListNode *head) struct ListNode *tail, *p; while (head&&head->data % 2 == 0) p = head; head = head->next; free(p); tail = head; p = tail->next; while (p != NULL) if (p->data % 2 == 0) tail->next = p->next; free(p); else tail = p; p = tail->next; return head;
以上是关于实验11-2-4 删除单链表偶数节点 (20 分)的主要内容,如果未能解决你的问题,请参考以下文章