数据结构-单线性链式-头插法

来源:互联网 发布:柯尔特蟒蛇357淘宝模型 编辑:程序博客网 时间:2024/06/07 00:07
#include<iostream>#include<stdlib.h> using namespace std;typedef struct Lnode{int data;struct Lnode* next;}Linknode;int main(){int n;while(cin>>n){Linknode *head,*p;head=(Linknode*)malloc(sizeof(Linknode));head->next=NULL;for(int i=0;i<n;i++){int data;cin>>data;p=(Linknode*)malloc(sizeof(Linknode));p->data=data;p->next=head->next;head->next=p;}while(p){cout<<p->data<<" "<<endl;p=p->next;}}return 0;}

原创粉丝点击