Dubly Linked List in C++ Example
General 2013. 7. 15. 11:42//
// main.cpp
// Test_01
//
// Created by Jang sang wook on 7/13/13.
// Copyright (c) 2013 Jang sang wook. All rights reserved.
//
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, const char * argv[])
{
struct node{
int data;
node* next;
node* prev;
};
node* head;
node* tail;
node* n;
node* temp;
n = new node;
n->data = 1;
n->prev = NULL;
head = n;
tail = n;
n = new node;
n->data = 2;
n->prev = tail;
tail->next = n;
tail = tail->next;
n = new node;
n->data = 3;
n->prev = tail;
tail->next = n;
tail = tail->next;
n = new node;
n->data = 4;
n->prev = tail;
tail->next = n;
tail = tail->next;
temp = head;
cout<<"Printing from head to tail\n";
while(temp!=NULL){
cout<< temp->data <<" ";
temp = temp->next;
}
cout<<endl;
temp = tail;
cout<<"\nPrinting from tail to head\n";
while(temp!= NULL){
cout<<temp->data<<" ";
temp = temp->prev;
}
return 0;
}
'General ' 카테고리의 다른 글
Hashtable과 HashMap의 비교 (0) | 2013.07.12 |
---|---|
자료구조 : 버블 정렬(Bubble Sort) 0(n^2) (0) | 2013.07.11 |
How to Create a Linked List C++ Introduction to Linked Lists - YouTube (0) | 2013.07.06 |
3n+1문제 (The 3n+1 Problem) (0) | 2013.06.19 |
Dead Reckoning (0) | 2012.02.27 |