Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //list header
- #ifndef LIST_H
- #define LIST_H
- #include <fstream>
- #include "node.h"
- template <class T, class E>
- class dlist {
- private:
- int length;
- T *head;
- T *tail;
- public:
- dlist()
- {
- head = 0;
- }
- void createDlist(string value, E x)
- {
- T *cu;
- T *temp;
- temp = new node(x);
- temp->data = value;
- temp->next = NULL;
- if (head == NULL)
- {
- temp->prev = NULL;
- head = temp;
- }
- else
- {
- T *cu = head;
- while (cu->next != NULL)
- cu = cu->next;
- cu->next = temp;
- temp->prev = cu;
- }
- }
- void printDlist() {
- T *temp = head;
- cout << "The linked list is as followed: " << endl;
- while (temp != NULL)
- {
- cout << temp->data << " " << endl;
- temp = temp->next;
- }
- cout << endl;
- }
- };
- #endif
- //node header
- #ifndef NODE_H
- #define NODE_H
- #include <string>
- using namespace std;
- class node {
- public:
- string data;
- node* next;
- node* prev;
- node(string x) {
- data = x;
- next = 0;
- prev = 0;
- }
- };
- #endif
- //main cpp
- #include "list.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- int main() {
- dlist <node> list;
- string line;
- ifstream myfile("input1.txt");
- if (myfile.is_open())
- {
- while (getline(myfile, line))
- {
- //cout << line << endl;
- list.createDlist(line);
- }
- list.printDlist();
- //myfile.close();
- }
- //else cout << "unable to open file";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement