akiitbhu
BAN USER
//taking input fronm a txt file named fb.txt
#include<stdio.h>
typedef struct node{
int weight;
int name;
int lw;
int rw;
struct node*left;
struct node*right;
}*NODEPTR;
NODEPTR ptree;
void inorder(NODEPTR p);
void print_bal(NODEPTR p);
void main()
{
ptree=0;
//input
int N;
FILE *f;
int i,b,wl,wr,bl,br,t;
f=fopen("fb.txt","r");
fscanf(f,"%d",&N);
NODEPTR bal[N];
for(i=0;i<N;i++)
{
bal[i]=(NODEPTR*)malloc(sizeof(struct node));
bal[i]->name=i;
bal[i]->left=0;
bal[i]->right=0;
bal[i]->weight=10;
bal[i]->lw=0;
bal[i]->rw=0;
}
//create tree
for(i=0;i<N;i++)
{
//if no balance then enter sothing above N
fscanf(f,"%d",&wl);
fscanf(f,"%d",&bl);
fscanf(f,"%d",&wr);
fscanf(f,"%d",&br);
if(bl<=N)
{
if(ptree==0)
ptree=bal[i];
bal[i]->left=bal[bl];
}
if(br<=N)
{
if(ptree==0)
ptree=bal[i];
bal[i]->right=bal[br];
}
bal[i]->lw=wl;
bal[i]->rw=wr;
//bal[i]->weight+=wl+wr;
}
print_bal(ptree);
inorder(ptree);
}
void inorder(NODEPTR p)
{
if(p!=0)
{
inorder(p->left);
printf("%d ->",p->weight);
inorder(p->right);
}
}
void print_bal(NODEPTR p)
{
int l,r;
if(p!=0)
{
print_bal(p->right);
print_bal(p->left);
if(p->left==0&&p->right==0) // printf("NOTHING TO ADD on :%c: w=%d\n",p->name,p->weight);
{
if(p->lw==0&&p->rw==0)
;//do nothing
else if(p->lw!=0&&p->rw==0)
{
printf("node :%d: add to R: %d \n",p->name,p->lw);
// p->weight=p->weight+p->lw;
p->rw+=p->lw;
}
else if(p->rw!=0&&p->lw==0)
{
printf("node :%d: add to L: %d \n",p->name,p->rw);
// p->weight=p->weight+p->rw;
p->lw+=p->rw;
}
else if(p->rw!=0&&p->lw!=0)
{
if(p->lw!=p->rw)
{
if(p->lw < p->rw)
{
printf("node :%d: add to L :%d\n",p->name,p->rw-p->lw);
// p->weight=p->weight+(p->rw-p->lw);
p->lw+=(p->rw-p->lw);
}
else
{
printf("node :%d: add to R :%d\n",p->name,p->lw-p->rw);
// p->weight=p->weight+(p->lw-p->rw);
p->rw+=(p->lw-p->rw);
}
}
}
p->weight+=(p->lw+p->rw); //updqte whole weight
}
else if(p->left==0&&p->right!=0)
{
l=p->lw;
r=p->rw+p->right->weight;
if(l!=r)
{
if(l>r)
{
printf("node :%d: add to R :%d\n",p->name,l-r);
p->rw+=l-r;
}
else
{
printf("node :%d: add to L :%d\n",p->name,r-l);
p->lw+=r-l;
}
}
p->weight+=p->rw+p->lw+p->right->weight;
}
else if(p->left!=0&&p->right==0)
{
l=p->lw+p->left->weight;
r=p->rw;
if(l!=r)
{
if(l>r)
{
printf("node :%d: add to R :%d\n",p->name,l-r);
p->rw+=l-r;
}
else
{
printf("node :%d: add to L :%d\n",p->name,r-l);
p->lw+=r-l;
}
}
p->weight+=p->rw+p->lw+p->left->weight;
}
else if(p->left!=0&&p->right!=0)
{
l=p->right->weight;
r=p->left->weight;
l=l+p->lw;
r=r+p->rw;
if(l!=r)
{
if(l>r)
{
printf("node :%d: add to R :%d\n",p->name,l-r);
p->rw+=(l-r);
}
else
{
printf("node :%d: add to L :%d\n",p->name,r-l);
p->lw+=(r-l);
}
}
p->weight+=p->rw+p->lw+p->right->weight+p->left->weight;
}
}
}
Repmarygaustria, Analyst at ADP
I am Mary from Los Angeles, USA. I am working as a Manager in Fragrant Flower Lawn Services company. I ...
Repaalexlingram, AT&T Customer service email at ABC TECH SUPPORT
I am Alex and I live in Colorado Springs . I am working as a International human resources manager and I ...
Repggeraldinejrivera, Aghori Mahakal Tantrik at ABC TECH SUPPORT
I am a fashion model, talented in runway turns and photoshoot prep. I Have worked at two displaying organizations and ...
Repannawellson007, Area Sales Manager at 8x8
Hey my name is anna And i am working as a content writer in Search engine optimization company.My component ...
RepHey, I am Ruth and I am working as an interviewer.I take too many Interviews For my Company and ...
Repgiannanewhart, Cloud Support Associate at ABC TECH SUPPORT
I am Clinical managers, a type of medical and health services manager, and work as managers in both administrative areas ...
Repivaharvie, Production Engineer at BMO Harris Bank
Je suis Iva, professeur de musique et compositeur avec plus de 6 ans d'expérience avec une connaissance approfondie de ...
Repreetaharriet, Applications Developer at Achieve Internet
As a sales clerk, I deal with customers on a daily basis. My work face-to-face assisting customers with finding the ...
Repharryhamesh, Android Engineer at ADP
I placement officers usually work in colleges and universities. One of My friends taught me about prayers that break curses ...
Repnp810929, Product Security Engineer at Absolute Softech Ltd
I am Neesha , a Creative news writer with 3+ years of experience at Audio Visions. Great storytelling skills and a ...
RepViennaJones, Reporter at Precious Moments
Experienced project manager and capable supervisor of a team of writers, reporters, illustrators, graphic artists, and other staff members. I ...
Replarryehickl, Associate at ABC TECH SUPPORT
I am a blogger in the Geek system operator . As an editor with a strong background in english and hindi ...
Reptaylamowll, Analyst at AMD
Aspire to work in a challenging environment, where my exceptional skills and abilities are completely explored, and I can easily ...
RepHelanZelda, Consultant at Advent
HelanZelda from Atlanta, GA, United States. I have a passion for exploring/sharing new ideas and experiences throughout the interdisciplinary ...
Rephelenweiver, Consultant at ASU
I am Helen , policy analyst at Sunflower Market , with 3 years of experience building and maintaining relationships with elected officials ...
Replimlocica, News reporter at Smitty's Marketplace
Hello, I am a News reporter. Master's Degree in astrology and News reporter and 10 years of experience working ...
Repdelenestanf0, HR Executive at Agilent Technologies
Hi, I am a Clinical social worker. methods of prevention and treatment in providing mental-health/healthcare services, I also have ...
int isno(char c);
- akiitbhu August 20, 2012void main()
{
char s[]="gs1t43fd86gd2b3m0",t; ///suppose we got
int i=0,j=0,k;
while(i<strlen(s))
{
if(isno(s[i]))
i++;
else
{
t=s[j];
s[j]=s[i];
if(i>j+1)
{
k=i;
while(k>j)
{
s[k]=s[k-1];
k--;
}s[j+1]=t;
}else
s[i]=t;
i++;j++;
}
}
printf("%s",s);
}
int isno(char c)
{
return (c<='9'&&c>='0')?1:0;
}
int ischar(char c)
{
return ((c<='z'&&c>='a')||(c<='Z'&&c>='A'))?1:0;
}