AlgoritmaNews Adalah Situs Berita Perkembangan Teknologi Terkini Yang Ter Update Setiap Hari | Mulai Dari Berita Teknoligi, Sains, Perbintangan, NASA, Satelit, Tips Trik Mengatasi Masalah Yang Terjadi Pada Prangkat Teknologi dan Masih Banyak Info Menarik Lainya.
Promo Web Hosting 500mb Bw Unlimited Cuma Rp.50rb Untuk 10 Pendaftar Pertama Order disini

Bantuan Para Master, Program Ini Dimana Salahnya ya ?

By. AlgoritmaNews -

Tolong di bantu, Ini coding Dimana Salah nya ya ?
saya pusing nih.. tidak ketemu masalahnya..



#include
#include
#include
#include"Node.h"
#include"List.h"

//Implementasi Node

*Node::*Node(int x,Node *p){
data=x;
next=p;
};
int Node::getData(){return data;};
Node *Node::getNext(){return next;};
void Node::setData(int x){data=x;};
void Node::setNext(Node *ptr){next=ptr;};

//Implementasi List

List::List(){
head_ptr=NULL;
tail_ptr=NULL;
numOfItems=0;
};
int List::size(){return numOfItems;};
Node * List::getHead(){return head_ptr;};
Node * List::getTail(){returnTail_ptr;};
bool List::isEmpty(){return(numOfItems==0);};
Node *List::search(int x){
Node * currentPtr=getHead();
while(currentPtr!=NULL){
if(currentPtr->getData()==x)
return currentPtr;
else
currentPtr=currentPtr->getNext();
}
return NULL; //Now x is not, so return NULL
};
Node *List::itemAt(int position){
if(position<0||position>=numOfItems)
return NULL;
Node * currentPtr=getHead();
for(int k=0;k!=position;k++)
currentPtr=currentPtr->getNext();
return currentPtr;
};
void List::removeHead(){
if(numOfItems==0)
return;
Node * currentPtr = getHead();
head_ptr=head_ptr->getNext();
delete currentPtr;
numOfItems--;
};
void list::removeTail(){
if(numOfItems==0)
return;
if(head_ptr==tail_ptr){
head_ptr=NULL;tail_ptr=NULL;
numOfItems=0;return;
}
Node *beforeLast=itemAt(numOfItems-2);
beforeLast->setNext(NULL);//beforeLast becomes last
delete tail_ptr;//deletes the last object
tail_ptr=beforeLast;
numOfItems--;
};
void List::remove(int x){
if(numOfItems==0)return;
if(head_ptr==tail_ptr&&head_ptr->getData()==x){
head_ptr=NULL;
tail_ptr=NULL;
numOfItems=0;
return;
]
Node * beforePtr=head_ptr;//beforePtr trails currentPtr
Node * currentPtr=head_ptr->getNext();
Node * tail=getTail();
while(currentPtr!=tail)
if(currentPtr->getData()==x){//x is found.Do the bypass
beforePtr->setNext(currentPtr->getNext());
delete currentPtr;
numOfItems--;
}
else{//x is not found yet. Forward beforePtr & currentPtr.
beforePtr=currentPtr;
currentPtr=currentPtr->getNext();
}
};
void List::insertHead(int x){
Node * newHead=newNode(x,head_ptr);
head_ptr=newHead;
if(tail_ptr==NULL)//only one item in list
tail_ptr=head_ptr;
numOfItems++;
};
void list::insertTail(int x){
if(isEmpty())
insertHead(x);
else{
Node * newTail=newNode(x);
tail_ptr->setNext(newTail);
tail_ptr=newTail;numOfItems++;
}
};
//inserts item x after the item pointed to by p
void List::insert(Node *p,int x){
Node *currentPtr=head_ptr;
while(currentPtr!=NULL&&curentPtr!=p)
currentPtr=currentPtr->getNext();
if(currentPtr!=NULL){//p is found
Node *newNd=new Node(x,p->getNext());
p->setNext(newNd);
numOfItems++;
}
};

//File Header : Node.h

class Node{
private:
int data; //different data type for other apps
Node *next;//the link pointer to next item
public:
Node(int x=0,Node * ptr=NULL);//constructor
int getData();
Node *getNext();
void setData(int x);
void setNext(Node *ptr);
};

//File Header : List.h

class list{
private:
Node *head_ptr;Node *tail_ptr;int numOfItems;
public:
List();//constructor
int size();
Node *getHead();
Node *getTail();
bool isEmpty();
Node *search(int x);
Node *itemAt(int position);
void removeHead();
void removeTail();
void remove(int x);//delete leftmost item having x
void insertHead(int x);
void insertTail(int x);
void insert(Node *p,int x);
};

tolong di bantu gan..
contact ya kalau bisa ke email -> tunick.kutuh@gmail.com
atau comment aja disini langsung


thx,

1 Comments:

kaga ada mainnya :)) wani piro :p wakakkaka

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Post a Comment

Loading..

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More