Pages

Saturday, 29 August 2015

C++ Program to insert a new nod and Value in Singly Link List


#include <iostream>
using namespace std;

struct nod
{
int data;
nod *next;
};

class myClass
{
private:

nod *head;
nod *current;
nod *temp;

public:
myClass()
{
head = NULL;
current = NULL;
}


void insert();

};



void myClass :: insert()
{
if (head == NULL)
{
head = new nod;
cout << " Insert Value: ";
cin >> head ->data;
head ->next = NULL;
}

else
{
current = head;
while(current->next != NULL)
{
current = current ->next;
}

temp = new nod;
cout << " Insert Value: ";
cin >> temp -> data;
temp->next = NULL;
current->next = temp;

}
}


int main ()
{
myClass m;
int choose;

A:
system("cls");
cout << endl;
cout << endl;
cout << " <1> Insert new value" << endl;
cout << endl;

cout << " Choose: ";
cin >> choose;
system("cls");

if (choose == 1)
{
m.insert();
goto A;
}

}


For any query email us : mohsin.mahmood@hotmail.co.uk

1 comment:

Ads.txt said...

its helpful. thankkyou sir