Operation on list - c++ program:
Write a program in c to Insert value on list and list iteration.
typedef struct item *node_ptr;
struct item {
int element;
node_ptr next;
}
typedef node_ptr list;
typedef node_ptr position;
void main()
{
list head;
void create(list);
void print(list);
head=(list)malloc(sizeof(struct item));
head->next=NULL;
create(head);
print(head);
}
void create(list head)
{
position temp;
char opt;
while (1)
{
printf("Enter yuor option\n");
flushall();
scanf("%c",&opt);
if(opt=='n'||opt=='N')
return;
if(head->next== NULL)
head->next=temp=(position)malloc(sizeof(struct item));
else
temp=temp->next=(position)malloc(sizeof(struct item));
temp->next =NULL;
scanf("%d",&temp->element);
}
}
void print(list head)
{ position temp;
temp =head->next;
while (temp !=NULL)
{
printf("%d",temp->element);
temp=temp->next;
}
}