//单???链???表??? #include <iostream> using namespace std; typedef char datatype; typedef struct node{ datatype data; struct node* next; }listnode; typedef listnode* linklist; listnode *p; //建??立???链???表??? linklist createlist() { linklist head = (listnode*)malloc( sizeof(listnode)); listnode *p,*r; r = head; char ch; while((ch=getchar())!=' ' ) { p = (listnode*)malloc( sizeof(listnode)); if(p==NULL) return NULL; p->data = ch; r->next = p; r = p; } r->next = NULL; return(head); } //查??找??单???链???表??? linklist getnode(linklist head , int i) { int j; listnode* p; p = head; j = 0; while(p->next && j<i) { p = p->next; j++; } if(i==j) return p; else return NULL; } //打???印??输??出?链???表???内??容?Y void printlist(linklist head) { listnode* p = head; while(p->next) { cout<<p->next->data<<endl; p = p->next; } } //插?入?? void insertlist(linklist head,datatype m,int i) { listnode* p = getnode(head,i); listnode* s = (listnode*)malloc( sizeof(listnode)); s->data = m; if(p!=NULL) { s->next = p->next; p->next = s; } } //删??除y一??个?结??点??,删??除y第???i个?后??面?的??那?个? void deletelistnode(linklist head,int i) { int j = 0; listnode *p,*r; p = head; while(p&&j<i) { p = p->next; j++; } if(p==NULL) exit(1); r = p->next; p->next = r->next; free(r); } int main() { linklist mylist = createlist(); // listnode * tmp = getnode(mylist,3); //cout<<tmp->data<<endl; //printlist(mylist); //insertlist(mylist,'a',2); //printlist(mylist); deletelistnode(mylist,2); printlist(mylist); return 0; }