abhishekism
BAN USER#include<iostream>
using namespace std;
int main()
{
int a[] = {1,2,3,55,6,4,2,1,6,7,9};
int b[] = {1,4,22,5,6,7,8,9,0,5,3};
int n = sizeof(a)/sizeof(a[1]);
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i < j && a[i]>b[j])
cout<<"("<<i<<","<<j<<")"<<endl;
}
}
return 0;
}
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
using namespace std;
struct Node{
int data;
struct Node* next;
};
struct Node * head;
void print(struct Node* temp)
{
int i=0;
cout<<"head->";
while(temp!= NULL)
{
cout<<temp->data<<"->";
temp =temp->next;
i++;
}
cout<<"NULL";
}
void list_remove_dup(Node * head)
{ struct Node *current;
struct Node *previous;
struct Node *runner;
struct Node *tmp;
if(head == NULL) return;
if(head->next == NULL) return;
current = head->next;
previous = head;
while(current != NULL){
runner = head;
while(runner != current){
// remove node if equal
if(runner->data == current->data){
tmp = current;
current = current->next;
previous->next = current;
delete tmp;
break;
}runner = runner->next;
}if(runner == current){
current = current->next;
previous = previous->next;
}
}
}
int main()
{
head = NULL;
Node* first = new Node;
Node* second = new Node;
Node* third = new Node;
Node* fourth = new Node;
Node * five = new Node;
Node * six = new Node;
Node * seven = new Node;
Node * eight = new Node;
Node * nine = new Node;
Node * ten = new Node;
head =first;
first->data = 1;
first->next = second;
second->data = 2;
second->next = third;
third->data = 1;
third->next = fourth;
fourth->data=3;
fourth->next =five;
five->data = 4;
five->next = six;
six->data = 3;
six->next = seven;
seven->data = 6;
seven->next = eight;
eight->data = 9;
eight->next = nine;
nine->data = 7;
nine ->next =ten;
ten->data =9;
ten->next =NULL;
print(head);
cout<<endl;
list_remove_dup(head);
print(head);
cout<<endl;
}
- abhishekism January 20, 2016