http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1068
This is a code that deletes a specific character in a linked list, and learns the first time a linked list has been written.
1#include <iostream>2#include <stdio.h>3#include <cstring>4#include <algorithm>5#include <math.h>6 using namespacestd;7 structSA8 {9 Charch;Ten structSA *Next; One }; A intShow (SA *t)//Print linked list - { - while(t->next!=NULL) the { -cout<<t->ch<<Endl; -T=t->Next; - } + return 0; - } + intDel (SA *t,CharData//clears the specified single character A { at while(t->next!=NULL) - { - if(t->next->ch==data) - { -T->next=t->next->Next; - Break; in } -T=t->Next; to } + return 0; - } the intMain () * { $SA *p,*Q;Panax Notoginseng Chardata; - intN; the while(cin>>N) + { Ap=q= (SA *)malloc(sizeof(SA));//Request a Space the for(intI=0; i<n;i++) + { -cin>>p->ch;//Assign Value $p->next= (SA *)malloc(sizeof(SA));//to link different spaces together $P=p->Next; - } -p->next=null;//The sign of the end of the space chain theCin>>data; - del (q,data);Wuyi Show (q); the } - return 0; Wu}
View Code
Linked list-deletion of data in a 1 linked list