解题思路:
注意事项:
参考代码:
#include<stdio.h> #include<string.h> #define MAX 100003 typedef struct cb{ int data[MAX]; int lengh; }ListNode; void PushBack(ListNode*head,int x); void DeletNode(ListNode*head,int x); void init(ListNode*head); //对数组版链表进行初始化 void Print(ListNode*head,int x); int main() { ListNode newNode; init(&newNode); int n,i,input,del; scanf("%d",&n); for(int i = 0;i<n;i++) { scanf("%d",&input); PushBack(&newNode,input); } scanf("%d",&del); // DeletNode(&newNode,del); Print(&newNode,del); return 0; } void init(ListNode*head) { int i = 0; for(i = 0;i<MAX;i++) { head->data[i] = 0; } head->lengh = 0; } void PushBack(ListNode*head,int x) { head->data[head->lengh++] = x; } void Print(ListNode*head,int x) { if(head->lengh<=0) { return ; } int flag = 0; for(int i = 0;i<head->lengh;i++) { if(head->data[i]!=x) { printf("%d ",head->data[i]); } else{ flag = 1; } } if(!flag) printf("NULL"); } void DeletNode(ListNode*head,int x) { int pos = -1; for(int i = 0;i<head->lengh;i++) { if(head->data[i]==x) { pos = i; break; } } if(pos!=-1) { for(int i = pos+1;i<head->lengh;i++) { head->data[i-1] = head->data[i]; } head->lengh--; } }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:814 |
C语言训练-计算1977!* (C语言代码)浏览:899 |
简单的a+b (C语言代码)浏览:493 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:534 |
C语言训练-计算1~N之间所有奇数之和 (C语言代码)浏览:651 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:460 |
C语言训练-数字母 (C语言代码)浏览:608 |
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:567 |
大神老白 (C语言代码)浏览:601 |
淘淘的名单 (C语言代码)浏览:1228 |