#include <iostream>
typedef int af[];
typedef struct Node
{
struct Node *next;
int data;
Node(int d = int()) :next(NULL), data(d){}
}Node;
Node* first = NULL;
#define LIST(ar,n) \
{ \
Node *p = first; \
for (int i = 0; i < n; i++)\
{ \
Node *s = new Node(ar[i]); \
if (p == NULL) \
{ \
first = s; \
p = first; \
} \
else \
{ \
s->next = p->next; \
p->next = s; \
p = s; \
} \
} \
} \
#define PRINT() \
{ \
Node *p = first; \
while (p != NULL) \
{ \
cout << p->data << " "; \
p = p->next; \
} \
} \
using namespace std;
int main()
{
int a[] = { 1, 2, 3, 4 };
LIST(a,sizeof(a)/sizeof(int));
PRINT();
return 0;
}
数据结构:define实现链表
最新推荐文章于 2022-11-16 23:00:23 发布