链表队列与栈
// 链表、队列和栈.cpp : 定义控制台应用程序的入口点。#include "stdafx.h"#include <iostream>using namespace std;class Student{public:int num;Student *head,*end,*next,*pre;};static int i = 0;Student *creat(void){Student *head,*end,*p1,*p2;cout<<"现在开始创建链表:"<<endl;end=head=p1=p2=new Student;cin>>p1->num;head->next=p1;p1->pre=head;if(p1->num!=0){cin>>p2->num;while(p2->num!=0){p1->next=p2;p2->pre=p1;p1=p1->next;p2=new Student;cin>>p2->num;}end->pre=p1;p1->next=end;delete p2;if(i==1)return (end);}else{head=end;delete p1,p2;}return (head);}Student *fun(Student *head,int k){Student *p;p=head;if(i!=1){ cout<<p->num<<" ";for(int z=0;z<k;z++){p=p->next;cout<<p->num<<" ";}}else{ cout<<p->num<<" ";for(int z=0;z<k-1;z++){p=p->pre;cout<<p->num<<" ";}}return head;}int main(){cout<<"要创建队列还是栈:"<<endl;cout<<"输入1创建立栈,输入2建立队列:"<<endl;cin>>i;Student *head = creat();cout<<"输入要出队或出栈的数量:"<<endl;int k;cin>>k;fun(head,k);return 0;}这究竟是怎么一回事,有错改不过来,时间来不及了,不改了。