Skip to content

Instantly share code, notes, and snippets.

@otarza
Created January 28, 2014 19:26
Show Gist options
  • Select an option

  • Save otarza/8674378 to your computer and use it in GitHub Desktop.

Select an option

Save otarza/8674378 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<iostream>
using namespace std;
struct node {
int x;
node *next;
node *prev;
};
int main()
{
node *root;
root = new node;
root->x = 0;
node *item1;
item1 = new node;
item1->x = 2;
item1->prev = root;
root->next = item1;
node *item2;
item2 = new node;
item2->x = 6;
item2->prev = item1;
item1->next = item2;
node *item3;
item3 = new node;
item3->x = 9;
item3->prev = item2;
item2->next = item3;
node *item4;
item4 = new node;
item4->x = 11;
item4->prev = item3;
item3->next = item4;
node *current;
current = root;
node *lastOdd;
node *firstOdd;
bool pirveladShemxvda = false;
while(true){
if(!pirveladShemxvda && current->x % 2 != 0) {
firstOdd = current;
pirveladShemxvda = true;
current->prev->next = current->next;
current->next->prev = current->prev;
current = current->next;
}
if(current->x % 2 != 0){
lastOdd = current;
}
cout<<current->x;
if(current->next == NULL){
break;
}
current = current->next;
}
cout<<endl;
cout<<lastOdd->x;
lastOdd->prev->next = lastOdd->next;
current = root;
cout<<endl;
while(true){
cout<<current->x;
if(current->next == NULL) break;
current = current->next;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment