Skip to content

Commit eff700a

Browse files
Merge branch 'smv1999:master' into Raunak
2 parents 63ea117 + bf61b35 commit eff700a

File tree

4 files changed

+120
-5
lines changed

4 files changed

+120
-5
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
## Contributing Guidelines
22

3-
Developers are highly welcome to contribute to this project by modifying the existing solutions to more optimized solutions or add new programs that fit into the various categories
4-
mentioned in the repo or adding a new category if needed.
3+
Developers are highly welcome to contribute to this project by modifying the existing solutions to more optimized solutions or add new programs that fit into the various categories mentioned in the repo or adding a new category if needed.
4+
5+
* Look at the issues created already and get yourself assigned for the issues by commenting there. Issues will be assigned on FCFS basis.
6+
* Create a new issue whether you are adding a new program or optimizing the existing solution. After the issue is assigned to you, start working on it and make a pull request as mentioned in the steps below.
57

68
1. Fork this repository
79
1. Clone the repo ```git clone <YOUR_FORKED_REPO_URL>```
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
3+
This is a Circular Doubly Linked List program which recursively reverses the Linked Lists.
4+
Since, it is a Ciruclar Doubly Linked List, both the forward and backward traversal is also possible.
5+
6+
*/
7+
8+
#include <iostream>
9+
10+
using namespace std;
11+
12+
/*
13+
14+
Node definition:
15+
1. Pointer to previous node.
16+
2. Integer Data
17+
3. Pointer to next node.
18+
19+
*/
20+
21+
class dcll_node {
22+
public:
23+
dcll_node* prev;
24+
int data;
25+
dcll_node* next;
26+
};
27+
28+
void createDCLL(dcll_node* &head) {
29+
30+
dcll_node* temp = head;
31+
32+
int choice;
33+
34+
do {
35+
36+
int data;
37+
38+
cout << "Enter Data : ";
39+
cin >> data;
40+
41+
dcll_node* newNode = new dcll_node();
42+
newNode->data = data;
43+
newNode->prev = NULL;
44+
newNode->next = NULL;
45+
46+
if(head == NULL) {
47+
head = newNode;
48+
temp = head;
49+
head->next = head;
50+
head->prev = head;
51+
} else {
52+
temp->next = newNode;
53+
newNode->prev = temp;
54+
temp = newNode;
55+
newNode->next = head;
56+
head->prev = newNode;
57+
}
58+
59+
cout << "Do you want to continue? (1/0) : ";
60+
cin >> choice;
61+
62+
} while(choice == 1);
63+
64+
}
65+
66+
dcll_node* recursive_reverse(dcll_node *head) {
67+
68+
if(head == NULL || head->next == head)
69+
return head;
70+
71+
head->prev->next = head->next;
72+
head->next->prev = head->prev;
73+
dcll_node* tHead = recursive_reverse(head->next);
74+
tHead->prev->next = head;
75+
head->prev = tHead->prev;
76+
head->next = tHead;
77+
tHead->prev = head;
78+
return tHead;
79+
}
80+
81+
void display(dcll_node* head) {
82+
83+
if(head == NULL)
84+
return;
85+
86+
cout << "The elements are : ";
87+
dcll_node* temp = head;
88+
89+
do {
90+
91+
cout << temp->data << " ";
92+
temp = temp->next;
93+
94+
} while(temp != head);
95+
cout << endl;
96+
}
97+
98+
int main() {
99+
100+
dcll_node* head = NULL;
101+
102+
createDCLL(head);
103+
104+
cout << "Before reversing : " << endl;
105+
display(head);
106+
107+
head = recursive_reverse(head);
108+
109+
cout << "After reversing : " << endl;
110+
display(head);
111+
112+
return 0;
113+
}

Data Structures/Linked Lists/Circular Doubly Linked Lists/reverse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
3-
This is a Circular Doubly Linked List program which deletes a Node at the end of the Linked Lists.
3+
This is a Circular Doubly Linked List program which reverses the Linked Lists.
44
Since, it is a Ciruclar Doubly Linked List, both the forward and backward traversal is also possible.
55
66
*/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 🎯💻Competitive Programming Question Bank🏆🏅
2-
This repository contains all the popular Competitive Programming questions and Interview questions. The Programming languages used for demonstration are the C Language, C++, Python, and Java. <br><br>
2+
This repository contains all the popular Competitive Programming questions and Interview questions. The Programming languages used for demonstration are the C Language, C++, Python, Java and JavaScript. <br><br>
33
[![Followers](https://img.shields.io/github/followers/smv1999?style=for-the-badge)](https://github.com/smv1999?tab=followers)
44
![GitHub forks](https://img.shields.io/github/forks/smv1999/CompetitiveProgrammingQuestionBank?style=for-the-badge)
55
![GitHub Repo stars](https://img.shields.io/github/stars/smv1999/CompetitiveProgrammingQuestionBank?style=for-the-badge)
@@ -81,7 +81,7 @@ Thanks goes to these **Wonderful People** 👨🏻‍💻:
8181
## Programs
8282
<img src="https://raw.githubusercontent.com/smv1999/CompetitiveProgrammingQuestionBank/master/images/devincept.gif" alt="DevIncept" />
8383

84-
<p>DevIncept is an 30 day open source program helping the student community learn and contribute in various open source project under the guidance of skilled mentors and project admins.</p>
84+
<p>DevIncept is a 30 day open source program helping the student community learn and contribute in various open source projects under the guidance of skilled mentors and project admins.</p>
8585

8686

8787
## Stargazers Over Time

0 commit comments

Comments
 (0)