#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void create();
void display();
void append();
struct node
{
int data;
struct node* next;
};
struct node* root;
int main()
{
//clrscr();
int ch;
char ch1='y';
while(ch1=='y')
{
printf("MENU\n");
printf("1 create node\n2 display\n3 appending\n enter your choice......");
scanf("%d",&ch);
switch(ch)
{
case 1:create();
break;
case 2:display();
break;
case 3:append();
break;
default:printf("invalid");
break;
}
printf("\ndo you want to enter more\n");
scanf(" %c",&ch1);
}
//getch();
}
void create()
{
node *head;
head=(node*)malloc(sizeof(node));
printf("eneter the data");
int a;
scanf("%d",&a);
head->data=a;
head->next=NULL;
root=head;
}
void display()
{
struct node* temp;
temp=root;
if(temp==NULL)
printf("empty");
else
{
printf("START-->");
while(temp!=NULL)
{
printf("%d-->",temp->data);
temp=temp->next;
}
printf("NULL");
}
}
void append()
{
struct node* temp;
temp=(node *)malloc(sizeof(node));
printf("enter data to append");
int d;
scanf("%d",&d);
temp->data=d;
temp->next=NULL;
if(root==NULL)
root=temp;
else
{
struct node *p;
p=root;
while(p!=NULL)
{
p=p->next;
}
p->next=temp;
}
}
#include<conio.h>
#include<stdlib.h>
void create();
void display();
void append();
struct node
{
int data;
struct node* next;
};
struct node* root;
int main()
{
//clrscr();
int ch;
char ch1='y';
while(ch1=='y')
{
printf("MENU\n");
printf("1 create node\n2 display\n3 appending\n enter your choice......");
scanf("%d",&ch);
switch(ch)
{
case 1:create();
break;
case 2:display();
break;
case 3:append();
break;
default:printf("invalid");
break;
}
printf("\ndo you want to enter more\n");
scanf(" %c",&ch1);
}
//getch();
}
void create()
{
node *head;
head=(node*)malloc(sizeof(node));
printf("eneter the data");
int a;
scanf("%d",&a);
head->data=a;
head->next=NULL;
root=head;
}
void display()
{
struct node* temp;
temp=root;
if(temp==NULL)
printf("empty");
else
{
printf("START-->");
while(temp!=NULL)
{
printf("%d-->",temp->data);
temp=temp->next;
}
printf("NULL");
}
}
void append()
{
struct node* temp;
temp=(node *)malloc(sizeof(node));
printf("enter data to append");
int d;
scanf("%d",&d);
temp->data=d;
temp->next=NULL;
if(root==NULL)
root=temp;
else
{
struct node *p;
p=root;
while(p!=NULL)
{
p=p->next;
}
p->next=temp;
}
}
No comments:
Post a Comment