首页 > 其他 > 详细

数据结构:define实现链表

时间:2015-08-11 14:16:00      阅读:191      评论:0      收藏:0      [点我收藏+]
#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实现链表

原文:http://blog.csdn.net/liuhuiyan_2014/article/details/47418379

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!