Skip to content

Commit

Permalink
Adding cpp linked list classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernulphus committed Oct 17, 2019
1 parent f97733f commit 649c190
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
30 changes: 30 additions & 0 deletions data_structures/lists/Cpp/list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<iostream>

#include<string>
#include<"list.h">

List::List(){
head = nullptr;
}

List::~List(){
}

void List::insert(std::string data){
Node *t = new Node(item,nullptr);
if (head == nullptr)
head=t;
else{
t->setNext(head);
head=t;
}
}

std::string List:getDebugString(){
std::string s = "";
Node *t = head;
while (t != nullptr){
s = s+t->getData() + "->";
t=t->getNext();
}
}
11 changes: 11 additions & 0 deletions data_structures/lists/Cpp/list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

class List{
private:

public:
List();
~List();
void List::insert(std::string data);
std::string List:getDebugString();
}
11 changes: 11 additions & 0 deletions data_structures/lists/Cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

#include <iostream>

#include "node.cpp"
#include "list.cpp"

int main()
{

return 0;
}
31 changes: 31 additions & 0 deletions data_structures/lists/Cpp/node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <iostream>
#include "node.h"
Node::Node() : next(nullptr)
{
}

Node::Node(std::string data){
this->data = data;
this->next = nullptr;
}

Node::Node(std::string data, Node *next){
this->data = data;
this->next = next;
}

void Node::setData(std::string data){
this->data = data;
}

void Node::setNext(Node *next){
this->next = next;
}

std::string Node::getData(){
return data;
}

Node* Node::getNext(){
return next;
}
15 changes: 15 additions & 0 deletions data_structures/lists/Cpp/node.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

class Node{
private:
std::string data;
Node *next;
public:
Node();
Node(std::string data);
Node(std::string data, Node* next);
void setData(std::string data);
void setNext(Node *next);
std::string getData();
Node* getNext();
};

0 comments on commit 649c190

Please sign in to comment.