2118数据结构实验之链表三:链表的逆置
2016-09-27 10:10
495 查看
2118数据结构实验之链表三:链表的逆置.
#include<iostream> #include<malloc.h> using namespace std; struct node { int data; struct node *next; }; struct node *creat() { struct node *head,*tail,*p;; int i; head=(struct node *)malloc(sizeof(struct node)); head->next=NULL; tail=head; while(p!=NULL)//条件为(p->data!=-1),将出现Runtime Error { p=(struct node *)malloc(sizeof (struct node )); cin>>p->data; p->next=NULL; tail->next=p; tail = p; if(p->data==-1) break; } return head; }; void rerserve(struct node *head) { struct node *p,*q; p=head->next; q=p->next; head->next=NULL; while(p->data!=-1) { p->next=head->next; head->next=p; p=q; if(q->data!=-1) q=q->next; } } void display(struct node *head) { struct node *q; q=head->next; while(q!=NULL) { cout << q->data; if(q->next!=NULL) cout<< " "; q=q->next; } cout<<endl; } int main() { int n,h; struct node *head; head=creat(); rerserve(head); display(head); return 0; }
相关文章推荐
- SDUT_2118 数据结构实验之链表三:链表的逆置
- 【2118】数据结构实验之链表三:链表的逆置
- 2118 数据结构实验之链表三:链表的逆置
- SDUTOJ 2118数据结构实验之链表三:链表的逆置
- SDUT 2118-数据结构实验之链表三:链表的逆置
- 【2118】数据结构实验之链表三:链表的逆置 (SDUT)
- 【2118】数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置 (SDUT 2118)
- 【2118】数据结构实验之链表三:链表的逆置 (SDUT)
- sdut 2118-数据结构实验之链表三:链表的逆置
- 2118数据结构实验之链表三:链表的逆置
- SDUT 2118数据结构实验之链表三:链表的逆置
- 暑假集训第1天链表-数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 寒假第二天--线性表-- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置