原创
链表的创建,翻转,打印
2008-11-9 15:15
2738
4
4
分类:
软件与OS
#include <iostream>
#include <conio.h>
using namespace std;
struct Node
{
char data;
struce Node* next;
};
Node* createLink()
{
Node *h,*p,*s;
p = new Nod;
char ch;
cout << "Enter the string:";
ch = getche();
if(ch == 13 || p == NULL)
{
cout << "Create Failed!" << endl;
if(ch != 13)
delete(p);
exit(0);
}
h = p;
p->data = ch;
while((ch = getche()) != 13)
{
s = new Node;
if(s == NULL)
exit(0);
p->next = s;
p = s;
}
p->next = NULL;
cout << endl;
return h;
}
Node* reverese(Node* link)
{
Node *pre,*cur,*ne;
pre = link;
cur = pre->next;
while(cur)
{
ne = cur->next;
cur->next = pre;
pre = cur;
cur = ne;
}
link->next = NULL;
return pre;
}
void display(Node* link)
{
Node* n = link;
while(n)
{
cout << n->data;
n = n->next;
}
}
void mian()
{
}
文章评论(0条评论)
登录后参与讨论