#include <iostream>
using namespace std;
struct MyList{
int val;
MyList *next;
};
void ListInsert(MyList *L, int i, int *e) {
int j = 1;
MyList *p;
p = L;
while (p && j < i) {
p = p->next;
j++;
}
if (!p || j > i) {
throw "ERROR!";
}
MyList *s = new MyList;
s->val = *e;
s->next = p->next;
p->next = s;
}
void ListDelete(MyList *L, int i, int *e) {
int j = 1;
MyList *p = L;
while (p && j < i) {
p = p->next;
j++;
}
if (!(p->next) || j > i) {
throw"ERROR";
}
MyList *q = p->next;
p->next = q->next;
*e = q->val;
free(q);
}
void GetElem(MyList *L, int i, int *e) {
int j = 1;
MyList *p;
p = L->next;
while (p && j < i) {
p = p->next;
j++;
}
if (!p || j > i) {
throw "ERROR!";
}
*e = p->val;
}
int main() {
MyList *head;
MyList *r;
head = new MyList;
head->next = NULL;
r = head;
for (int i = 0; i < 10; i++) {
MyList *p = new MyList;
p->val = i;
r->next = p;
r = p;
}
r->next = NULL;
int *e = new int(-1);
r = head->next;
while (r) {
cout << r->val << endl;
r = r->next;
}
return 0;
}
|