Untitled

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

using namespace std;

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

node* list=NULL;
node* l1=NULL;
node* l2=NULL;

void dumplist(node* list)
{
	if(list!=NULL)
	{
		int i=1;
		node* ylist=list;
		do
		{
			cout<<" Listenin "<<i++<<" .Nodunun Adresi: "<<list<<" Datasý: "<<list->data<<" Linki: "<<list->link<<endl;
		    list=list->link;
		}while(list!=ylist);
	}
}

node * newnode()
{
	node* newnode=new node;
	newnode->link=newnode;
	return newnode;
}

node* last(node* list)
{
	if(list!=NULL)
	{
		node* ylist=list;
		while(list->link!=ylist)
		list=list->link;
	}
	node* last=list;
	return last;
}
void addhead(node* node_, node*& list)
{
	if(node_!=NULL)
	if(list==NULL)
	list=node_;
	else
	{
		node_->link=list;
		last(list)->link=node_;
		list=node_;
	}
}

void concatenate(node*& l1, node* l2)
{
	if(l2!=NULL)
	if(l1==NULL)
	l1=l2;
	else
	{
		last(l1)->link=l2;
		last(l2)->link=l1;
	}
}

node* cons(int data_)
{
	node* cons;
	cons=newnode();
	cons->data=data_;
	return (cons);
}

node* copy(node* list)
{
	node* suret=NULL;
	node* ylist=list;
	if(list!=NULL)
	do
	{
		concatenate(suret, cons(list->data));
		list=list->link;
	}while(list!=ylist);
	return suret;
}

node* locate(int data_, node* list)
{
	node* locate=NULL;
	if(list!=NULL)
	{
		node* ylist=list;
		do
		{
			if(list->data!=data_)list=list->link;
			else
			{
				locate=list;
				break;
			}
		}while(list!=ylist);
	}
	return locate;
}

bool member(node* node_, node* list)
 {
 	node* ylist=list;
 	while(list!=ylist && list!=node_)
 	list=list->link;
 	bool member=(list==node_);
 	return(member);
 }
 
 node* cuthead(node*& list)
 {
 	node* cuthead=list;
 	node* ylist=list;
 	if(list!=ylist)
 	{
 		list=list->link;
 		cuthead->link=ylist;
	}
	return(cuthead);
 }
 
 void free(node*& list)
 {
 	node* ylist=list;
 	delete ylist;
 }
 
 bool advance(node*& point)
 {
 	bool advance=false;
 	node* ylist=list;
 	if((point!=ylist)&&(point->link=ylist))
 	{
 		point=point->link;
 		advance=true;
	 }
	 return (advance);
 }
 
 bool deletenode(node* node_, node*& list)
 {
 	bool deletenode=false;
 	node* ylist=list;
 	if(list==ylist)
 	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));
	 } 
 }