Beruflich Dokumente
Kultur Dokumente
h>
#include<stdlib.h>
struct node
int data;
};
void append()
temp->left=NULL;
temp->right=NULL;
scanf("%d",&temp->data);
if(root==NULL)
root=temp;
else
p=root;
while(p->right!=NULL)
p=p->right;
p->right=temp;
temp->left=p;
}
}
void addatloc()
int i=1,loc;
scanf("%d",&loc);
scanf("%d",&temp->data);
temp->left=NULL;
temp->right=NULL;
p=root;
while(i<loc)
p=p->right;
i++;
temp->right=p;
temp->left=p->left;
p->left->right=temp;
p->left=temp;
void display()
while(p!=NULL)
{
printf("%d\t",p->data);
p=p->right;
int length()
int count=0;
temp=root;
while(temp!=NULL)
count++;
temp=temp->right;
return(count);
void Delete()
int loc;
scanf("%d",&loc);
if(loc>length())
printf("invalid location");
else if(loc==1)
{
root=root->right;
root->left=NULL;
else if(loc==length())
p=root;
while(p->right!=NULL)
p=p->right;
q=p->left;
q->right=NULL;
p->left=NULL;
free(p);
else
int i=1;
while(i<loc)
k=k->right;
i++;
k->left->right=k->right;
k->right->left=k->left;
k->right=NULL;
k->left=NULL;
free(k);
void addatorigin()
scanf("%d",&temp->data);
temp->left=NULL;
temp->right=NULL;
temp->right=root;
root->left=temp;
root=temp;
int main()
int i=1,num;
scanf("%d",&num);
while(i<=num){
append();
i++;}
display();
printf("%d\n",length());
addatorigin();
display();
printf("%d\n",length());
addatloc();
display();printf("\n");
printf("%d\n",length());
Delete();
display();
return(0);