Code:
/*double link list with user value
List
|
sprit
/ \
small larg
/ \
delete Even delete ODD
\ /
Display
*/
#include<iostream>
using namespace std;
struct node
{
int data;
node *next;
node *pre;
}*head;
struct node* create()
{
struct node *newnode=new node;
cout<<"Enter a value:";
cin>>newnode->data;
newnode->next=NULL;
newnode->pre=NULL;
return newnode;
}
void insertatend()
{
node *newnode=create();
node *temp=head;
if(head==NULL)
{
head=newnode;
}else
{
while(temp->next!=NULL)
temp=temp->next;
temp->next=newnode;
newnode->pre=temp;
}
}
void print()
{
node *temp=head;
cout<<"\n\nList:";
while(temp!=NULL)
{
cout<<" "<<temp->data;
temp=temp->next;
}
}
void even()
{
node *temp=head;
cout<<"\nEven :";
while(temp!=NULL)
{
if(temp->data%2==0)
{
cout<<" "<<temp->data;
}temp=temp->next;
}
}
void odd()
{
node *temp=head;
cout<<"\nODD :";
while(temp!=NULL)
{
if(temp->data%2==0)
{}else{
cout<<" "<<temp->data;
}temp=temp->next;
}
}
void small()
{
node *temp=head;
cout<<"\nSmall :";
while(temp!=NULL)
{
if(temp->data>29)
{}else
{
cout<<" "<<temp->data;
}temp=temp->next;
}
}
void great()
{
node *temp=head;
cout<<"\nGreat :";
while(temp!=NULL)
{
if(temp->data>29)
{
cout<<" "<<temp->data;
}temp=temp->next;
}
}
main()
{
head=NULL;
for(int x=0;x<4;x++)
insertatend();print();even();odd();small();great();
}
Output:
0 Comments