基于visual Studio2013解决C语言竞赛题之1070删除相同节点
生活随笔
收集整理的這篇文章主要介紹了
基于visual Studio2013解决C语言竞赛题之1070删除相同节点
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目
解決代碼及點評
/************************************************************************/ /* 70. 有兩個鏈表a和b。設結點中包含學號、姓名。 從a鏈表中刪除與b鏈表中有相同學號的那些結點*/ /************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h>typedef struct student STU; struct student {int num;char name[10];struct student * next; }; STU * Init() {STU * p=(STU *)malloc(sizeof(STU));if (p==NULL){return NULL;}elsep->next=NULL;return p; } void Insert(STU * head,int num,char * name) { STU * last=head;if (last==NULL){return;}while(last->next!=NULL)last=last->next;STU *p=(STU *)malloc(sizeof(STU));if (p==NULL){return;}else{p->num=num;strcpy_s(p->name,name);last->next=p;p->next=NULL;} } void DeleteNode(STU* pre,STU *cur) {pre->next=cur->next;free(cur); } void printfNodes(STU *head) {STU *p=head->next;while(p!=NULL){printf("%5d",p->num);p=p->next;}printf("\n"); } void main() {STU * A=Init();Insert(A,1,"abc");Insert(A,2,"abc");Insert(A,3,"abc");Insert(A,4,"abc");STU * B=Init();Insert(B,5,"abc");Insert(B,3,"abc");Insert(B,6,"abc");Insert(B,7,"abc");printfNodes(A);printfNodes(B);STU *p1=A;STU *p2=B;p2=p2->next;p1=p1->next;STU *p=A;while(p1!=NULL){ p2=B->next;while(p2!=NULL){ if (p1->num==p2->num){DeleteNode(p,p1);p1=p->next;break;;}p2=p2->next;}p1=p1->next;p=p->next;}printfNodes(A);system("pause"); }代碼編譯以及運行
由于資源上傳太多,資源頻道經常被鎖定無法上傳資源,同學們可以打開VS2013自己創建工程,步驟如下:
1)新建工程
2)選擇工程
3)創建完工程如下圖:
4)增加文件,右鍵點擊項目
5)在彈出菜單里做以下選擇
6)添加文件
7)拷貝代碼與運行
程序運行結果
代碼下載
http://download.csdn.net/detail/yincheng01/6681845
解壓密碼:c.itcast.cn
轉載于:https://www.cnblogs.com/new0801/p/6177414.html
總結
以上是生活随笔為你收集整理的基于visual Studio2013解决C语言竞赛题之1070删除相同节点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 今天我解决的sql中文乱码问题
- 下一篇: 基于visual Studio2013解