A blog to help students to learn programming in various languages including C, C++, Java, Python and many more.

Subscribe For Free Latest Updates!

We'll not spam mate! We promise.

Sunday 24 January 2016



Program Screenshot
Output

#include <iostream>
using namespace std;
struct node {
int info;
node* link;
}*start,*nNode;
node * createNew(int in) {
nNode = new node;
nNode->info=in;
return (nNode);
}
node display(node* temp) {
while(temp!=NULL) {
cout<<temp->info<<"  ";
temp=temp->link;
}
cout<<"\n";
}
node * search(node* tempPtr,int item) {
while(tempPtr!=NULL && tempPtr->info!=item) {
tempPtr=tempPtr->link;
}
return (tempPtr);
}
int main()
{
int n=2,s,item;
int a[8]={7,9,8,5,4,6,2,1};
start=NULL;
node* tempPtr;
for (int i = 0; i < 8; ++i)
{
if(start==NULL) {
start=createNew(a[i]);
start->link=NULL;
} else {
nNode=createNew(a[i]);
nNode->link=start;
start=nNode;
}
}
cout<<"Elements of linked list: \n";
display(start);
cout<<"Enter element you want to search: ";
cin>>item;
tempPtr=search(start,item);
if (tempPtr!=NULL && tempPtr->info==item) {
cout<<"Item found in list.\n";
} else {
cout<<"Item doesn't exists in list.\n";
}
return(0);
}

1 comments : Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.



Copyright © 2016 - ProgrmIt - All Rights Reserved
(Articles Cannot Be Reproduced Without Author Permission.)
Design By : | Powered By: Blogger