Skip to content

Added comments for better understanding #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions doubly linked list.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include<bits/stdc++.h>
using namespace std;
class Node{
class Node{ //Defining a node
public:
int data;
Node* next;
Node* prev;
Node(){
Node(){ //Constructor
data = 0;
next = NULL;
prev = NULL;
}
Node(int x){
Node(int x){ //Constructor
data = x;
next = NULL;
prev = NULL;
Expand All @@ -32,7 +32,7 @@ class List{
temp->next = newnode;
newnode->prev = temp;
}
void print(){
void print(){ //Function to print the doubly linked list
Node* temp = head;
while (temp != NULL){
cout << temp->data << " ";
Expand Down Expand Up @@ -67,7 +67,7 @@ class List{
temp = temp->next;
}
}
int getsize(){
int getsize(){ //Method to find the size of the doubly linked list
Node* temp = head;
int size = 0;
while (temp != NULL){
Expand All @@ -76,7 +76,7 @@ class List{
}
return size;
}
void append_at_head(int data){
void append_at_head(int data){ //Adding a node at the beginning of the doubly Linked List
Node* newnode = new Node(data);
if (head == NULL){
head = newnode;
Expand All @@ -88,9 +88,9 @@ class List{
}
}
};
int main(){
List l;
l.append(100);
int main(){
List l; //Defining an object l of class List
l.append(100); //Adding nodes
l.append(100);
l.append(100);
l.append(100);
Expand Down Expand Up @@ -131,4 +131,4 @@ int main(){
l.append_at_head(100);
l.print();
return 0;
}
}