#include<stdio.h>
#include<conio.h>
include<stdlib.h>
struct node
{
int info;
struct node *next;
};
struct node *makenode (int n)
{
struct node *t;
t=(struct node *) malloc(sizeof (struct node));
t->info=n;
t->next=NULL;
return t;
}
void makelist (struct node *list
{
int i, n, rum;
printf("How many node: ");
scanf ("%d", &n, ;
For (i=1; i<=n; i++)
{
scanf("%d",&num);
list->next=>namenode(num);
list=list->next;
}
}
void printlist (struct node *list)
{
printf("\nList contains: \n");
while (list->next!=NULL)
{
printf("%5d",list->next->info);
list=list->next;
}
}
int countlist(struct node *list)
{
int count=0;
while(list->next!=NULL)
{
count++;
list=list->next;
}
return count;
}
void insertfirst
(struct node *list)
{
int n;
struct node *t;
printf("\nEnter any
number to insert first: ");
scanf ("%d",
&n.);
t=makenocie (n);
t->next-list->next;
list->next=3t;
}
void deletefirst (struct node list)
{
struct node *t;
t=list->next->next;
free (list->next);
#include<conio.h>
include<stdlib.h>
struct node
{
int info;
struct node *next;
};
struct node *makenode (int n)
{
struct node *t;
t=(struct node *) malloc(sizeof (struct node));
t->info=n;
t->next=NULL;
return t;
}
void makelist (struct node *list
{
int i, n, rum;
printf("How many node: ");
scanf ("%d", &n, ;
For (i=1; i<=n; i++)
{
scanf("%d",&num);
list->next=>namenode(num);
list=list->next;
}
}
void printlist (struct node *list)
{
printf("\nList contains: \n");
while (list->next!=NULL)
{
printf("%5d",list->next->info);
list=list->next;
}
}
int countlist(struct node *list)
{
int count=0;
while(list->next!=NULL)
{
count++;
list=list->next;
}
return count;
}
{
int n;
}
void deletefirst (struct node list)
{
struct node *t;
list-next%3Dt%;
}
Void insertlast (st cuct
node list)
{
int n;
struct node *t;
printf("\nEnter any
number to insert last: ");
scanf ("%d",
&r):
while
(list->next!=NULL) List=list->next;
1ist->next-makenode
(n);
}
void deletelast (struct node list)
{
while (list->next->next!-NULL)
{
int n;
}
void deletelast (struct node list)
{
while (list->next->next!-NULL)
list=list->next;
free(list->next);
list->next = NULL;
}
void insertmiddle (struct node *list)
{
int n,
}
void insertmiddle (struct node *list)
{
int n,
count,i,p;
struct node t;
count->count list (list);
printf("\nEnter any position to
insert: ");
scanf("%d", &p);
if(p<1 11 p>count+1)
printf("Insert is impossible";
else
{
for (i=1; i<p; i++)
scanf("%d", &p);
printf("Insert is impossible";
else
{
for (i=1; i<p; i++)
1ist=list->next;
printf("after any number to insert
middle”);
scanf ("%d", &n);
t=make node (n);
t->next->list->next;
list->next=t;
}
}
void delete middle (struct node *list)
{
int count, i,p;
struct node *t;
Count=countiist (1ist);
printf("\nEnter any position to
delete: ");
scanf("%d", &p);
if (p<1 || p>count)
printf("Celete is impossible"},
alse
{
for (i-1; i<p; 1++)
1ist=list->next;
t=list->next->next;
free (list->next);
list->next=t;
}
}
void main()
{
int n, choice;
struct node *list:
int=(struct node *) malloc(sizeof (struct
node));
makelist (list):
do
{
clrscr ():
print list (list);
printf("\r.Enter your cliocie from
1 to 7.");
printf("\r1. Insert First.");
}
}
void delete middle (struct node *list)
{
int count, i,p;
struct node *t;
scanf("%d", &p);
printf("Celete is impossible"},
alse
{
for (i-1; i<p; 1++)
1ist=list->next;
t=list->next->next;
free (list->next);
list->next=t;
}
}
void main()
{
int n, choice;
makelist (list):
do
{
clrscr ():
printf("\r1. Insert First.");
printf("\r2. Insert
Middle.");
printf("\r3. Insert Last.");
printf("\r4. Delete First.");
printf("\r5. Delete Middle.");
printf("\r6. Delete Last.");
printf("\r7. Exit\n");
scanf ("%d", &choice);
switch (chcice)
{
case 1:
insertfirst (list);
break;
case 2:
insertmiddle (list);
break:
case 3:
insertlast (list);
break;
case 4:
deletefirst (list):
break;
case 5:
deletemiddle (list);
break;
case 6:
deletelist (list);
break:
case 7:
printf("\nThe program is now
exit.");
printf("\nPress any key to continue”);
break;
default:
printf("\nYour choice out of range.
");
printf("\nPlease try again.");
print list (list);
getch ();
}
while(choice! =7);
}
printf("\r3. Insert Last.");
printf("\r4. Delete First.");
printf("\r5. Delete Middle.");
printf("\r6. Delete Last.");
printf("\r7. Exit\n");
scanf ("%d", &choice);
{
case 1:
insertfirst (list);
break;
case 2:
printf("\nPress any key to continue”);
printf("\nPlease try again.");
}
while(choice! =7);
}
No comments:
Post a Comment