Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.3 kB
1
Indexable
Never
#include <iostream>
#include <conio.h>
#include <iomanip>

using namespace std;

struct node {
	int data;
	node* link;
};

	node* list=NULL;
	node* l1=NULL;
	node* l2=NULL;
	
//FONKSÝYON 1
void dumplist(node* list)
{
	int i=1;
	while(list!=NULL)
	{
		cout<<setw(8)<<"Listenin "<<setw(8)<<i++<<".Nodunun Adresi= "<<list
						     <<setw(8)<<"	Datasi=	"<<list->data
						     <<setw(8)<<"	Linki= "<<setw(8)<<list->link<<endl;
		list=list->link;
	}
}
//FONKSÝYON 2
node* newnode()
{
	node* newnode= new node;
	newnode->link=NULL;
	return(newnode);
}
//FONKSÝYON 3
node* last(node* list)
{
	if(list!=NULL)
	while(list->link!=NULL)
		list=list->link;
	node* last=list;
	return(last);
}
//FONKSÝYON 4
void addhead(node* node_, node*& list)
{
	node_->link=list;
	list=node_;
}
//FONKSiYON 5
void concatenate(node*& l1, node* l2)
{
	if(l1==NULL)
		l1=l2;
	else
		last(l1)->link=l2;
}
//FONKSÝYON 6
node* cons(int data_)
{
	node* cons;
	cons=newnode();
	cons->data=data_;
	return(cons);
}
//FONKSÝYON 7
node* copy(node* list)
{
	node* suret=NULL;
	if(list!=NULL)
	do
	{
		concatenate(suret,cons(list->data));
		list=list->link;
	}
	while(list!=NULL);
return(suret);
}
//FONKSÝYON 8
node* locate(int data_, node* list)
{
	node* locate=NULL;
	while(list!=NULL)
		if(list->data!=data_)
			list=list->link;
		else
		{
		locate=list;
		break;
		}
	return(locate);
}
//FONKSÝYON 9
bool member(node* node_, node* list)
{
	while(list!=NULL && list!=node_)
		list=list->link;
	bool member=(list==node_);
	return(member);
}
//FONKSÝYON 10
node* cuthead(node*& list)
{
	node* cuthead=list;
	if(list!=NULL)
	{
		list=list->link;
		cuthead->link=NULL;
	}
	return(cuthead);
}
//FONKSÝYON 11
void free(node*& list)
{
	delete list;//sor!
}
//FONKSÝYON 12
bool advance(node*& point)
{
	bool advance=false;
	if((point!=NULL)&&(point->link!=NULL))
	{
		point=point->link;
		advance=true;
	}
	return(advance);
}
//FONKSÝYON 13
bool deletenode(node* node_, node*& list)
{
	bool deletenode=false;
	if(list==NULL)
		return(deletenode);
	if(list==node_)
	{
		node* degisken=cuthead(list);
		free(degisken);
		deletenode=true;
		return(deletenode);
	}
	else
	{
		node* point=list;
		do
		{
			if(point->link==node_)
			{
				node* degisken1=cuthead(point->link);
				free(degisken1);
				deletenode=true;
				return(deletenode);
			}
		}
		while(advance(point));
	}
}