链表
开发工具与关键技术:VS2019 ,C++
作者:陆滕
撰写时间:2019年5月28日
Step1:定义链表结构
Step2:编写方法完成链表创建。控制台输入链表节点值,输入0结束
Step3:编写方法在链表头部插入新节点,在链表尾部插入新节点
Step4:编写方法在某个节点p的前面插入新节点
Step5:编写方法在某个节点p的后面插入新节点
Step6:编写方法删除头节点
Step7:编写方法删除某个节点p
Step8 : 编写方法输出链表
Node* CreateNodesList() {
Node* head=NULL, * s, * p;
int a;
cin >> a;
while (a)
{
s = new Node;
s->date = a;
s->next = NULL;
if (head==NULL)
{
head = s;
}
else
{
p = head;
while (p->next)
{
p = p->next;
}
p->next = s;
}
cin >> a;
}
return head;
}
void InsertHead(Node*&head) {
int a;
cin >> a;
Node* p = new Node;
p->date = a;
p->next = NULL;
p->next = head;
head = p;
}
void InsertTail(Node*head) {
int a;
cin >> a;
Node* s, * p;
s = new Node;
s->date = a;
s->next = NULL;
p = head;
while (p)
{
if (p->next==NULL)
{
s->next = p->next;
p->next = s;
p = s;
}
p = p->next;
}
}
void InsertBefore(Node*head, Node*p) {
int a;
cin >> a;
Node* p1, * q;
Node* s = new Node;
s->date = a;
p1 = head;
while (p1)
{
q = p1;
if (s->next = p)
{
s->next = p;
q->next = s;
break;
}
}
}
void InsertAfter(Node*p)
{
int a;
cin >> a;
Node* q = new Node;
q->date = a;
q->next = NULL;
q->next = p->next;
p->next = q;
}
bool DelHead(Node*& head) {
if (true)
{
Node* s;
s=head;
head = head->next;
}
return false;
}
bool DelNode(Node* head, Node* node)
{
Node*p;
p = node;
if (true)
{
head->next = p->next;
}
return false;
}
void ListNodes(Node*head)
{
while (head)
{
cout << head->date << "\t";
head = head->next;
}
cout << endl;