Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
August 16th, 2008, 05:53 PM
|
#1 (permalink)
| | Junior Member
Join Date: Aug 2008
Posts: 5
| ^_^ the beautiful princess Eve Hi
Everyone
I need help
I ask what is the solution to this program
Or I should explain how the solution & In an ancient land, the beautiful princess Eve had many suitors. She decided on the following procedure to determine which suitor she would marry . first , all of the suitor would be lined up one after the other and assigned number. The first suitor would be number1, the second number 2, and so on up to the last suitor ,number n . starting at the suitor in the first position. She would then count three suitors down the line ( because of the three letters in her name) and the third suitor would be eliminated from winning her hand and removed from the line. Eve would then continue, counting three more suitors, and eliminate every third suitor. When she reached the end of the line. She would continue counting from the beginning. For example, if there were 6 suitors . the elimination proceed as follows: 123456 initial list of suitors , start counting from1 12456 suitor 3 eliminated , continue counting form 4 1245 suitor 6 eliminated , continue counting form 1 125 suitor4 eliminated , continue counting form 5 15 suitor 2 eliminated , continue counting form 5 1 suitor 5 eliminated , 1 is the lucky winner. Write a program that creates a circular linked list of nodes to determine which position you should stand in to marry the princess if there are n suitors. Your program should simulate the elimination process by deleting the node that corresponds to the suitor that is elimination for each step in the process With thanks
Yuki
^_^ |
| |
August 16th, 2008, 06:06 PM
|
#2 (permalink)
| | Junior Member
Join Date: Aug 2008
Posts: 5
|
pLZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ |
| |
August 16th, 2008, 07:03 PM
|
#3 (permalink)
| | Ultimate Member
Join Date: Mar 2005 Location: Out of my mind
Posts: 2,742
|
Ugh, it's the weekend and I'm not much in algorithm mode
I take it you're in a Data Structures class...fun stuff. A cicular linked list just joins the tail node to the head node so you don't need a "head" AND "tail" pointer.
At this point in class (or whatever) you should now how to make a linked list; it's not hard. It's structure would probably be:
struct Node {
int SuitorNumber; // data element
Node *next; // point to next node
}
Then you would fill this list with 1....n suitors. You'll want procedures like:
Add_Node
Delete_Node
Find_Node
Display_Node
You'll want a Start_Pointer variable to point to beginning of list and note that the "next" pointer of the LAST node will be the same as Start_Pointer (circular).
Too much fun; I miss my college days 
Last edited by Rootstonian : August 16th, 2008 at 07:14 PM.
|
| |
August 16th, 2008, 07:15 PM
|
#4 (permalink)
| | Junior Member
Join Date: Aug 2008
Posts: 5
|
Please help me not have tried enough time
I am a mother of two children age two months and I do not have enough time please
Can you please fully resolved |
| |
August 16th, 2008, 07:28 PM
|
#5 (permalink)
| | Ultimate Member
Join Date: Mar 2005 Location: Out of my mind
Posts: 2,742
|
LOL  Sorry...I did my college days and earned my 2 degrees.
If you don't have enough time to devote 100+% to your education, then you may want to wait till you can.
I have no problems HELPING you with debugging or coding problems, but I will not write code for you  Besides, you would fail a test if asked in a question to code a Insert_Node function in a singular linked list (about 15 lines of code  ) |
| |
August 16th, 2008, 07:54 PM
|
#6 (permalink)
| | Junior Member
Join Date: Aug 2008
Posts: 5
| |
| |
August 16th, 2008, 09:50 PM
|
#7 (permalink)
| | Sea-Ninja wannabe
Join Date: Apr 2002 Location: Albany, Ga.
Posts: 8,244
|
O, My! 
__________________
They say technology slows down for no one. I know it outruns my wallet. I figure its because my wallet isn't light enough yet.
|
| |
August 23rd, 2008, 04:47 AM
|
#8 (permalink)
| | Junior Member
Join Date: Aug 2008
Posts: 2
|
public class list
{
private class Node
{
private int Snum;
private Node link;
public Node()
{
Snum = 0;
link = null;
}
public Node(int newSnum, Node linkValue)
{
Snum = newSnum;
link = linkValue;
}
}
private Node head;
public list()
{
head = null;
}
public void addToStart(int newSnum)
{
head = new Node(newSnum,head);
}
public boolean deleteHeadNode()
{
if (head!=null)
{
head = head.link;
return true;
}
else
return false;
}
public int size()
{
int count = 0;
Node position = head;
while (position != null)
{
count++;
position = position.link;
}
return count;
}
public boolean contains(int num)
{
return (find(num) != null);
}
private Node find(int target)
{
Node position = head;
int SnumAtPosition;
while(position!=null)
{
SnumAtPosition = position.Snum;
if(SnumAtPosition==target)
return position;
position = position.link;
}
return null;
}
public void outputList()
{
Node position = head;
while (position != null)
{
System.out.println(position.Snum);
position=position.link;
}
}
public boolean isEmpty()
{
return (head == null);
}
public void clear()
{
head = null;
}
public int selectsuitor(int n)
{
Node current = head;
Node prev=null;
while(n!=1)
{
for(int i=1;i<3;i++)
{
prev=current;
System.out.print(" " + current.Snum);
current=current.link;
if(current==null)
{
current=head;
}
}
prev.link=current.link;
current=current.link;
if(current==null)
{
current=head;
}
n--;
}
return current.Snum;
}
}
import java.util.Scanner;
public class list2{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
int numsuitors;
lab8list list = new lab8list();
System.out.println("Enter number of suitors:");
numsuitors = kb.nextInt();
for (int i=numsuitors;i>0;i--)
{
list.addToStart(i);
}
int x=list.selectsuitor(numsuitors);
System.out.println("\n\n"+ x);
}
im a smart girl  |
| |
August 23rd, 2008, 10:50 PM
|
#9 (permalink)
| | Ultimate Member
Join Date: Mar 2005 Location: Out of my mind
Posts: 2,742
|
Oh really? How did this piece of work compile and/or run? |
| |
August 25th, 2008, 05:47 PM
|
#10 (permalink)
| | Junior Member
Join Date: Aug 2008
Posts: 2
|
LOL  Sorry...
i asked for help
I thought it dificult
like writing in english
but some one helped me to understand it
{ How di d thi s pi ec e o f w or k c om pil e and/or run? }  you do not need my answer
but because you did your college days and earned your 2 degrees  .
I may need you someday
thanx  |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |