- 注册时间
- 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; //节点的指针域指向下一个节点
}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 ->data[0] ='*';//随便输入的
s =(LinkList)malloc(sizeof(ListNode));
gets(s->data); //从键盘中取一串不超过20的字符串
while (s->data[0] != 'Q' && s->data[0] !='q')//如果第一个字符是Q/q则退出
{
r->next = s;
r = s;
s =(LinkList)malloc(sizeof(ListNode));
gets(s->data);
}
r->next = NULL;
return head;
}
void printList(LinkList head) //输出链表
{
ListNode *p;
int i = 0;
if (head != NULL)
{
p =head;
while (p->next != NULL)
{
char data[20];
p = p->next;
while(p->data[i] != '\0')
{
i++;
}
for (;i>=0;i--)
{
cout <<p->data[i-1];
}
cout <<endl;
cout <<p->data<<endl;
i=0;
}
}
}
int main(int argc,char* argv[])
{
LinkList list;
list = CreateList();
printList(list);
} |
|