Skip to content
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

Added code to make an even-after-odd LL based on the data values #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
98 changes: 98 additions & 0 deletions EvenAfterOdd-LinkedList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include<iostream>
using namespace std;
class node{
public:
int data;
node * next;
node(int data){
this->data=data;
this->next=NULL;
}
};
node* arrange_LinkedList(node* head)
{

node*oh=NULL;
node*ot=NULL;
node*eh=NULL;
node*et=NULL;
while(head!=NULL)
{
if((head->data)%2!=0)
{
if(oh==NULL)
{
oh=head;
ot=head;
}
else
{ ot->next=head;
ot=head;
}
}
else
{
if(eh==NULL)
{
eh=head;
et=head;
}
else
{
et->next=head;
et=head;
}
}
head=head->next;
}

if(oh==NULL)
{ et=NULL;
return eh;
}
if(eh==NULL)
{
ot=NULL;
return oh;
}
et=NULL;
ot->next=eh;
return oh;

}

node* takeinput(){
int data;
cin>>data;
node* head=NULL,*tail=NULL;
while(data!=-1){
node *newnode=new node(data);
if(head==NULL) {
head=newnode;
tail=newnode;
}
else{
tail->next=newnode;
tail=newnode;
}
cin>>data;
}
return head;
}
void print(node *head)
{
node*temp=head;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
int main()
{
node*head=takeinput();
head=arrange_LinkedList(head);
print(head);
return 0;
}
16 changes: 16 additions & 0 deletions TowerOfHanoi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
using namespace std;
void towerOfHanoi(int n, char source, char auxiliary, char destination) {

if(n==0)
return;
towerOfHanoi(n-1, source, destination, auxiliary);
cout<<source<<" "<<destination<<'\n';
towerOfHanoi(n-1, auxiliary, source, destination);
}

int main() {
int n;
cin >> n;
towerOfHanoi(n, 'a', 'b', 'c');
}