Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 16:50

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Need Help On Implementing The Intersection Function.

Discussion on Need Help On Implementing The Intersection Function. within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2008
Posts: 14
Received Thanks: 2
Need Help On Implementing The Intersection Function.

I Made The Union Function For AUB But I've Been Having Trouble To Code The Function To Find Intersection A|B Base On The Union Function. Could Someone Help Please?

This Is The Code To Find The Union From Two Sets A & B.
Code:
#include <iostream>
using namespace std;

template<class T>
class OLL
{
private:struct NODE
		{
			T info;
			NODE *next;
		};
		NODE *list;
public: OLL()
		{
			list = NULL;
		}
		void insert (T x)
		{
			NODE *p = list, *q = list, *r;
			//create new node
			r = new (NODE); r -> info = x;
			r -> next = NULL;

			//find the insertion place
			while (p != NULL && p -> info < x)
			{
				q = p; p = p -> next;
			}
			if (p == list) // x is the first info
			{
				list = r; r -> next = p;
			}
			else if (p == NULL) // x is the last info
			{
				q -> next = r;
			}
			else //x is neither first nor last info
			{
				r -> next = p; q -> next = r;
			}
		}
		void display ()
		{
			NODE *p = list;
			while (p != NULL)
			{
				cout<<p->info<<" --> ";
				p = p -> next;
			}
			cout << "NULL\n";
		}
		void display (OLL <T> Tset)
		{
			while (Tset.list != NULL)
			{
				cout<<Tset.list -> info<<" --> ";
				Tset.list = Tset.list -> next;
			}
			cout<<"NULL\n";
		}
		void FindAUB(OLL setA, OLL setB, OLL &U)
		{
			NODE *a = setA.list;
			NODE *b = setB.list;
			while (a != NULL && b != NULL)
			{
				if (a->info < b->info)
				{
					U.insert(a->info);
					a = a->next;
				}
				else if (b->info < a->info)
				{
					U.insert(b->info);
					b = b->next;
				}
				else
				{
					U.insert(a->info);
					a = a->next;
					b = b->next;
				}
			}
			while (a != NULL)
			{
				U.insert(a->info);
				a = a->next;
			}
			while (b != NULL)
			{
				U.insert(b->info);
				b = b->next;
			}
		}
};
int main()
{
	//create set of integers
	OLL <int> setA, setB, setAUB;

	//insert set A
	int A[4] = {3, 9, 6, 8};
	int B[7] = {17, 19, 2, 6, 4, 1, 3};

	//set A
	for (int i=0; i<4; ++i)
	{
		setA.insert(A[i]);
	}
	setA.display();

	//set B
	for (int i=0; i<7; ++i)
	{
		setB.insert(B[i]);
	}
	setB.display();

	//set AUB
	setA.FindAUB(setA, setB, setAUB);
	setAUB.display();

	//Terminate Program
	system("pause");
	return 0;
}
phoenixsoju is offline  
Reply


Similar Threads Similar Threads
Implementing blowfish cyphor.
03/03/2013 - CO2 Private Server - 3 Replies
Hey everyone! I've been sitting here for hours attempting to convert my 5017 to accept blowfish. Some guidance and or help would be muchly be appreciated. Anyone ever done this?
Problem implementing new maps.
02/16/2013 - Metin2 Private Server - 1 Replies
Hi epvp, I've problem implementing some new map, when I implement all good, I reboot and server like starts normally but.. when I try to enter.. error connecting. In my syserr of the ch nothing, just in db and auth. Auth SYSERR: Feb 14 21:15:57 :: hupsig: SIGHUP, SIGINT, SIGTERM signal has been received. shutting down. SYSERR: Feb 14 21:17:06 :: socket_connect: HOST localhost:15000, could not connect. DB SYSERR: Feb 14 21:17:05 :: Start: TABLE_POSTFIX not configured use default
implementing quests in sro
01/04/2012 - SRO Private Server - 2 Replies
I would like to make my own quests in sro, but i don't know whit what i should begin with. Got some big ideas with really cool feature's, that im probably willing to share them with you when they are ready. If i succeed in what i want to do, the first server that will have this new type of quests will be DuckRoad. Thank you.
Joymax plans on implementing HackShield!
01/18/2010 - Gaming News - EN - 20 Replies
It seems that Joymax has paid AhnLab to use their HackShield System for Silkroad Online. Their new security should be implemented in a near future. They have signed the contract on October 27, 2009. The new system could be implemented as soon as possible. Will it be a final revolution for the game silkroad-online to stop the bots? This could be a major change in the future of the game, which is currently played 90% by bots (as some statistics proove). Source:24 HOUR NEWS CHANNEL...
Implementing Game Hacks
12/30/2006 - Conquer Online 2 - 9 Replies
Okay well don't im really new to this but what exactly do you do with the RAR file when you download it? thanks for your replies in advanced =D



All times are GMT +2. The time now is 16:50.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.