answersLogoWhite

0


Best Answer

To insert a value after a node in a linked list, first allocate and initialize the node, then add it to the current node...

newnode* = new node (n);

newnode->next = current.next;

if (current != head) current->next = newnode; else head = newnode;

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

#include<iostream.h>

#include<conio.h>

#include<process.h>

class list

{

public:

int info;

list *link;

};

class link_list

{

public:

list *head;

link_list()

{

head=NULL;

}

void insertf();

void deletef();

void show();

};

void link_list::insertf()

{

int item;

list *temp;

cin>>item;

temp=new list;

temp->info=item;

temp->link=NULL;

if(head==NULL)

head=temp;

else

{

temp->link=head;

head=temp;

}

}

void link_list::deletef()

{

list *temp;

if(head==NULL)

{

cout<<"Deleted item is:"<<temp->info;

head=temp->link;

}

}

void link_list::show()

{

list *temp;

if(head==NULL)

cout<<"List is empty:";

else

{

temp=head;

while(temp!=NULL)

{

cout<<temp->info;

temp=temp->link;

}

}

}

void main()

{

int ch;

link_list l1;

clrscr();

do

{

cout<<"\n Press 1 foe insertion";

cout<<"\n Press 2 for deletion";

cout<<"\n Press 3 for show";

cout<<"\n Press 4 for exit";

cin>>ch;

switch(ch)

{

case 1:

l1.insertf();

break;

case 2:

l1.deletef();

break;

case 3:

l1.show();

break;

case 4:

cout<<"Exit";

break;

default:

cout<<"You have entered wrong choice";

break;

}

}while(ch=4);

getch();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to Write a c plus plus program to insert a value n after the node in the linked list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program using recursion which should take two values and display 1st value raised to the power of second value?

Write a program using recursion which should take two values and display 1st value raised to the power of second value.


Write a program using 8086 instructions to double a number?

There isn't a reason to write a complete program to do this; in any assembly language just shift the value 1 bit to the left to double it.


Write a java script program to print first ten odd natural numbers in C?

Q.1 Write a program to print first ten odd natural numbers. Q.2 Write a program to input a number. Print their table. Q.3 Write a function to print a factorial value.


A c program to square matrix?

A C program to square matrix is a math problem. In the math problem you write down all the outer boundary values of matrix in a circle, then write down the inner value.


How do you write a c program which calculates the value of money at the end of each year of investment?

Reference:cprogramming-bd.com/c_page3.aspx#calculates the value of money


Pointer is a variable holding a memory address?

pointer is a derived datatype which contains memory addresses as their values. program:- #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int m=5,*p; clrscr(); p=&amp;m; printf("address of variable m is %p",(void *)p); }


How do you write a c program to find square of a no using call by value?

int square (int N) return N*N;


Write a complete well-documented C language program The program should repeatedly ask for another input of a non-negative real number ie X until a negative value is inputted and the program then?

Yes, do that, because it is your homework.


Why do you have to use the return type for the main function in c language i mean to what does the main function have to return the value to?

It returns the value to the operating system or whatever process launched it. If you launched your program from a batch file then the batch file can detect this return value. If your program is spawned or launched by another program then the return value goes to that parent prgoram or process. One more thing is that you can write main() without the return type and it will be absolutely correct


How do you Write a program in 'c' language which accepts int numbers from the users print its reverse number x function which return value?

question clarity


What does it mean to write the value for each digit in the number?

it means to write the value. for example.... 1.639. just write the value.


How do you write a c program that divides the value of a real number by two and displays them on the screen?

void foo (double val) { printf ("Full value: %f\n", val); printf ("Half value: %f\n", val/2); }