标签:style blog class code java ext
CBaseY* pY1 = static_cast<CBaseY*>(pX); // 错误,编译未通过, 类型指向是无关的 (解释:指针变量PX是CBaseX类,现在要将其转换为CBaseY类(和CBasex毫无关系))
CBaseY* pY1 = dynamic_cast<CBaseY*>(pX); // pY最终等于0(编译通过,但是转换未成功),前提是pX必须包含虚函数
#include<iostream> #include<stdio.h> #include <string> #include<conio.h> typedef struct student { int data; struct student *next; struct student *pre; }dnode; dnode *create() //尾插法建立带头结点的双链表 { dnode *head,*p,*s; int x=0; head=(dnode *)malloc(sizeof(dnode)); head->data=0; head->pre=NULL; head->next=NULL; p=head; printf("please input data (end by 0):"); scanf("%d",&x); while(x!=0) { s=(dnode *)malloc(sizeof(dnode)); s->data=x; s->pre=p; s->next=p->next; p->next=s; p=s; printf("please input data (end by 0):"); scanf("%d",&x); } return head; }; void delnode(dnode *head,int num) { dnode *p=head->next; while(p!=NULL) { if(num==p->data) { p->pre->next=p->next; if(p->next!=NULL) //最后一个节点 p->next->pre=p->pre; free(p); break; } p=p->next; } printf("could not find the node\n"); } void display1(dnode *head) //正向打印 { dnode *p=head->next; while(p!=NULL) { printf("%d ",p->data); p=p->next; } printf("\n"); } void display2(dnode *head)//反向打印 { dnode *p=head; while(p->next!=NULL) { p=p->next; } while(p->pre!=NULL) { printf("%d ",p->data); p=p->pre; } printf("\n"); } void main() { dnode *head=create(); delnode(head,4); display1(head); display2(head); }
标签:style blog class code java ext
原文地址:http://www.cnblogs.com/yexuannan/p/3704409.html