- 注册时间
- 2011-3-6
- 最后登录
- 1970-1-1
该用户从未签到
|
#include "stdafx.h"
#include <iostream>
#include<stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string>
#include <conio.h>
using namespace std;
#define N 20;
typedef char DataType; //定义节点数据域类型
typedef struct node //节点类型定义
{
DataType data[20];
struct node *next; //节点的指针域指向下一个节点
struct node *pre;
}ListNode;
typedef ListNode *LinkList;
ListNode *p; //定义节点指针
LinkList head; //定义链表头指针
ListNode * CreateList() //创建链表
{
char ch[20];
LinkList head = (LinkList) malloc (sizeof(ListNode)); //生成头结点
ListNode *s,*r;
r = head;
head->pre=NULL;
head ->data[0] ='*'; //随意写的
s =(LinkList)malloc(sizeof(ListNode));
gets(s->data);
while (s->data[0] != 'Q' && s->data[0] !='q') //按Q q退出
{
r->next = s;
s->pre = r;
r = s;
s =(LinkList)malloc(sizeof(ListNode));
gets(s->data);
}
r->next = NULL;
free(s);
return head;
}
void printList(LinkList head) //输出链表
{
ListNode *p;
int i = 0;
if (head != NULL)
{
p =head;
while (p->next != NULL)
{
p = p->next;
}
while (p->pre != NULL)
{
cout <<p->data<<endl;
p = p->pre;
}
}
}
int main(int argc,char* argv[])
{
LinkList list;
list = CreateList();
printList(list);
} |
|