ASHISH
BAN USERI am a b.tech 3rd year student of DTU(DCE), India
persuing in software engg
#include<iostream>
using namespace std;
struct node
{
int k;
node *next;
};
node *HEAD = NULL;
node *l1=NULL,*l2=NULL,*l1_end=NULL;
node *create(int v)
{
node *n = new node;
n->k = v;
n->next = NULL;
return n;
}
void build(node *n)
{
if(HEAD == NULL)
HEAD = n;
else
{
node *m = HEAD;
while(m->next != NULL)
m = m->next;
m->next = n;
}
}
void show()
{
node *m = HEAD;
cout<<endl;
while(m!=NULL)
{
cout<<m->k<<"->";
m = m->next;
}
cout<<"NULL";
}
void sort()
{
node *m = HEAD;
if(l1->k <= l2->k)
{
HEAD = m = l1;
l1 = l1->next;
}
else
{
HEAD = m = l2;
l2 = l2->next;
}
while((l1 != l1_end) && (l2 != NULL))
{
if(l1->k <= l2->k)
{
m->next = l1;
m = m->next;
l1 = l1->next;
}
else
{
m->next = l2;
m = m->next;
l2 = l2->next;
}
}
while(l1 != l1_end)
{
m->next = l1;
m = m->next;
l1 = l1->next;
}
while(l2 != NULL)
{
m->next = l2;
m = m->next;
l2 = l2->next;
}
m->next = NULL;
}
void separate()
{
node *m = HEAD;
while(m!=NULL)
{
if((m->next != NULL) && (m->k > m->next->k))
{
l1 = HEAD;
l1_end = l2 = m->next;
sort();
return;
}
m = m->next;
}
cout<<"List is not compatible.";
}
int main()
{
int x;
char ch;
do
{
cout<<"Enter the key : ";
cin>>x;
build(create(x));
cout<<"Want to enter more (y/n) ? : ";
cin>>ch;
}while(ch == 'y');
show();
separate();
show();
return 0;
}
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char str[80];
void rev(int l, int r)
{
char temp;
while(l<r)
{
temp = str[l];
str[l] = str[r];
str[r] = temp;
l++,r--;
}
}
void fun()
{
int start = 0, last = strlen(str)-1;
rev(start, last);
last = 0;
while(start < strlen(str))
{
while(str[last] != ' ' && str[last] != '\0')
last++;
rev(start, last-1);
while(str[last] == ' ' && str[last] != '\0')
last++;
start = last;
}
}
int main()
{
cout<<"Enter the string : ";
gets(str);
fun();
cout<<"Output : ";
puts(str);
return 0;
}
#include<iostream>
using namespace std;
class array
{
public:
int *a;
int s;
array()
{
cout<<"Enter the size of array : ";
cin>>s;
a = new int[s];
cout<<"Enter the array : ";
for(int i = 0; i<s; i++)
{
while(true)
{
cin>>a[i];
if(a[i]>=0 && a[i]<10)
break;
cout<<"Renter this digit please :";
}
}
}
void operator++();
void show()
{
for(int i=0; i<s; i++)
cout<<a[i]<<",";
}
};
void array::operator++()
{
int carry = 1;
int i=s;
for(; i>=0; i--)
{
if(a[i] + carry <=9)
{
a[i] += carry;
carry = 0;
i = -99;
}
else
a[i] = 0;
}
if(carry == 1 && i ==-1)
{
s++;
for(int i=s-1; i>0; i--)
a[i] = a[i-1];
a[0] = 1;
}
}
int main()
{
array arr;
++arr;
cout<<"The ++array is :";
arr.show();
return 0;
}
bool flag = true;
list *node = HEAD;
if(HEAD==NULL)
{
HEAD = myNode;
myNode->next = HEAD;
}
else{
while(flag)
{
if(node->key < myNode->key)
{
if(node->next->key >= myNode->key || node->next == HEAD)
{
list *temp;
temp = node->next;
node->next = myNode;
myNode->next = temp;
flag = false;
}
else
node = node->next;
}
}
}
- ASHISH October 29, 2012#include<iostream>
using namespace std;
#define MAX_SIZE 50
int n[MAX_SIZE][MAX_SIZE];
int size,temp;
int main()
{
cout<<"Enter the size of aquare matrix : ";
cin>>size;
cout<<"\nEnter the array : ";
for(int i=0; i<size; i++)
{
for(int j =0; j<size; j++)
cin>>n[i][j];
}
cout<<"\nEntered array id : ";
for(int i=0; i<size; i++)
{
cout<<endl;
for(int j =0; j<size; j++)
cout<<n[i][j]<<" ";
}
//transforming the matrix
for(int i=0; i<size-1; i++)
{
for(int j =i+1; j<size; j++)
{
temp =n[i][j];
n[i][j] = n[j][i];
n[j][i] =temp;
}
}
//upside down the matrix
for(int i=0; i<size/2; i++)
{
for(int j =0; j<size; j++)
{
temp =n[i][j];
n[i][j] = n[size-1-i][j];
n[size-1-i][j] = temp;
}
}
cout<<"\nRotated array is : ";
for(int i=0; i<size; i++)
{
cout<<endl;
for(int j =0; j<size; j++)
cout<<n[i][j]<<" ";
}
return 0;
}
}
- ASHISH January 28, 2013