#include <iostream>
#include <stdlib.h>
#include <stdio.h> using namespace std; //Node Class class Node { private: int data; Node next, prev; public: int get(){ return data; } void set(int a){ data = a; }
Node* getNext(){
return next;
}
void setNext(Node *x){
next = x;
}
Node* getPrev(){
return prev;
}
void setPrev(Node *x){
prev = x;
}
};
//Doubly Link List Class
class DList {
private:
Node head, current;
int size;
public:
// Constructor
DList(){
head = current = NULL;
size = 0;
}
// add function
void add(int x){
Node newNode = new Node();
newNode->set(x);
if( head == NULL ){
head = current = newNode;
newNode->setNext(NULL);
newNode->setPrev(NULL);
}
else{
if(current->getNext()==NULL){
newNode->setNext(NULL);
}
else{
newNode->setNext(current->getNext());
(current->getNext())->setPrev(newNode);
}
current->setNext(newNode);
newNode->setPrev(current);
current = newNode;
}
size++;
}
// get Function
int get(){
if (current != NULL)
return current->get();
}
// next Function
void next(){
if (current != NULL && current->getNext() != NULL){
current = current->getNext();
}
}
// remove Function
void remove(){
if( size>0 ){
if( current == head ){
//if its the 1st Node of List
head = head->getNext();
head->setPrev(NULL);
delete current;
current = head;
}
else if( current->getNext() != NULL ){
//if its the any central node of List
Node temp = current;
(current->getPrev())->setNext(current->getNext());
(current->getNext())->setPrev(current->getPrev());
current = current->getNext();
delete temp;
}
else if( current->getNext() == NULL ){
//if its the last node of the List
current = current->getPrev();
delete current->getNext();
}
size--;
}
else{
cout<<"List is Empty\n";
}
}
//display Function
void display(){
Node temp = head;
for (int i=1; i<=size; i++){
cout<<temp->get()<<", ";
temp = temp->getNext();
}
cout<<endl;
}
// start Function
void start(){
current = head;
}
// findRemoveDuplicate Function
/void findRemoveDuplicate(){
Node temp1 = head, temp2, prev;
cout<<"Duplicate: ";
while(temp1 != NULL){
temp2 = temp1->getNext();
prev = temp1;
while(temp2 != NULL){
if(temp1->get() == temp2->get()){
cout<<temp2->get()<<", ";
prev->setNext(temp2->getNext());
temp2->setNext(NULL);
delete(temp2);
temp2 = prev->getNext();
size--;
}
else{
temp2 = temp2->getNext();
prev = prev->getNext();
}
}
temp1 = temp1->getNext();
}
cout<<"\nNOTE: Setting current pointer to the start after removing duplicates\n";
start();
}/
};
//Main Function main(){ DList l1; int x; // adding data for (int i=1; i<=5; i++){ cout<<"Enter Data for Node "<<i<<endl; cin>>x; l1.add(x); }
cout<<"List is: \n";
l1.display();
}
Hi can you pls give a suggestion of how to do these with recursive functions for the home appliances website.
Please save me with this asap!
Print the list in forward order Print the list in reverse order Print the following three lines (in this order): "The first node contains <value in first node>"
"The last node contains <value in last node>"
"The first node contains <value in first node>"
Print the sum of all the values in the list. Returns the sum of all the values in the list. Returns the sum of all the values in the list (again, but done differently), sum them up going backwards through the list. Returns the average of all the values in the list. Return the value in the middle node. Move the data from the first node to the last node. Move the data from the first node to the last node, and the data from the last node to the first node. Make the first node the last node, and the last node the first node (don’t just move the data, move the entire node). Remove every even node (consider the first node, the one pointed to by head, to be node 1, an odd node).
Thank you so much for this. I was into this issue and tired to tinker around to check if its possible but couldnt get it done. Now that i have seen the way you did it, thanks guys with regards vidmate.onl/download
shaliniv
Your article is very meticulous and impressive to me, I hope to receive more good articles. can you pls give suggest for how to write code for "buttons" in table with out using any plugins for the cool appliances website