Skip to content
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');
}