?? main.cpp
字號:
#include <cstdlib>
#include <iostream>
using namespace std;
typedef struct node
{
int data;
struct node * next;
}Node;
typedef Node* Node_pointer;
Node_pointer list_creat(int n)
{
Node_pointer head, tail, p;
tail = head = new Node;
for (int i = 0 ; i < n ; i++)
{
p = new Node;
p->data = rand() % 1000;
tail->next = p;
tail = p;
}
tail->next = NULL;
return head;
}
bool list_insert(Node_pointer head, int x, int m)
{
Node_pointer p,q,tmp;
for (p = head->next ; p && p->data != x ; p = p->next);
if (!p) return false;
tmp = p->next;
for (int i = 0 ; i < m ; i++) {
q = new Node;
q->data = rand() % 1000;
p->next = q;
p = p->next;
}
p->next = tmp;
return true;
}
int list_delete(Node_pointer head, int min, int max)
{
int count = 0;
Node_pointer tmp;
for (; head->next ;)
{
if (head->next->data > min && head->next->data < max)
{
tmp = head->next;
head->next = head->next->next;
delete tmp;
count++;
}
else
head = head->next;
}
return count;
}
void display(Node_pointer head)
{
for (head = head->next ; head ; head = head->next)
cout << head->data << ' ';
cout << endl;
}
int main(void)
{
int count;
int n, m, x;
int min, max;
Node_pointer head;
cin >> n;
head = list_creat(n);
display(head);
cin >> x >> m;
if (!list_insert(head, x, m))
cout << "節(jié)點為找到" << endl;
display(head);
cin >> min >> max;
count = list_delete(head, min, max);
cout << "total delete " << count << endl;
display(head);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -