/*
* @Issue: 建立一个有头结点的单向链表,链表结点中数据通过键盘输入,输入到-1结束,头结点不放数据
* @Author: 一届书生
* @LastEditTime : 2020-02-09 10:27:10
*/
#include<iostream>
using namespace std;
typedef struct node{
int data;
struct node *next;
}Node,* Pnode;
// 初始化
Pnode craetlist(){
Pnode p,q,ph; //q:头结点 p:插入的结点
ph=new Node[sizeof(node)];
q=ph;
int a;
cin>>a;
while(a!=-1){
p=new Node[sizeof(node)];
p->data=a;
q->next=p;
q=p;
cin>>a;
}
q->next=NULL;
return (ph);
}
int main(){
Pnode head;
head=craetlist();
Pnode p=head;
while(p->next!=NULL){
p=p->next;
cout<<p->data<<endl;
}
return 0;
}
/*
* @Issue: 建立一个双向链表,数据域info,前趋指针pre,后继指针next,并输出这个双向链表
* @Author: 一届书生
* @LastEditTime : 2020-02-09 10:35:43
*/
#include<iostream>
using namespace std;
typedef struct node{
int info;
struct node *pre,*next;
}Node,* Pnode;
void printl(Pnode head){
Pnode p;
p=head->next;
while(p!=NULL){
cout<<p->info;
p=p->next;
}
}
int main(){
return 0;
}
原文:https://www.cnblogs.com/52dxer/p/12286366.html