c++/data structure

This is a discussion on c++/data structure within the C++ Programming forums, part of the General Programming Boards category; the problem is:the sequential search alogirthm will always find the first occurrence of an item in a data set creat ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    c++/data structure

    the problem is:the sequential search alogirthm will always find the first occurrence of an item in a data set creat a new sequential search method that takes a second integer argument indicating whichoccurrence of an item you want to search for
    the problem is in the forloop
    and i want to know is this code is right?
    Code:
    #include<iostream>
    using namespace std;
    
    int i;
    	int myarr[10];
    	 int t=myarr[i];
    	
    	int key;
    	int index;
    int seqsearch(int myarr())
    	
    for(i=0;i<10;i++)
    
    	{
    		
    		  for(int j=i-1;j>=0 && t<myarr[j];j--)
    		{
    
    
    		myarr[i]=rand()%100;
    		cout<<myarr[i]<<endl;
    	}
    	}
    
    void main()
    {
    
    	
    	int myarr[10];
    	 int t=myarr[i];
    	
    	int key;
    	int index;
    	cout<<"plz enter the key"<<endl;
    	cin>>key;
    
    
    
    		bool found=false;
    
    		for(int i=0;i<10;i++)
    
    		{
               for(int j=i-1;j>=0 && t<myarr[j];j--)
    		   {
    			   myarr[i]=rand()%100;
    		cout<<myarr[i]<<endl;
    			if(myarr[i]==key)
    			
    				
    				 found=true;
    					index=i;
    			}
    		   
    		}
    		
    
    
    		if(found==false)
    			
    		else cout<<"invalid key"<<endl ;
    		
    	}

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,657

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    45

    Cross posting?

    Is there a problem with posting the same question on numerous boards? Why even point that out. Perhaps someone who doesn't frequent this site could explain something in a way thats easier to understand for a particular person.

    the problem is in the forloop
    and i want to know is this code is right?
    It sounds like your supposed to make an algorithm template to search for the Xth occurance of type <Y> in sequence Z. It doesn't appear you are very well versed in STL and should do some studying
    Last edited by Incantrix; 10-31-2010 at 12:07 PM.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Is there a problem with posting the same question on numerous boards?
    It's somewhat rude, to be honest. I see it as akin to getting a second opinion from another doctor before you've even talked to the first doctor. If you're so distrustful of the first doctor, why even bother wasting his time? Now, if you don't get sufficient help from one forum (a rare occurrence if you put any effort into seeking help) it makes sense to try another, but the shotgun approach of firing your question off on multiple forums so you can cherry pick the best initial answer reeks of laziness and disrespect.

    >Perhaps someone who doesn't frequent this site could explain something
    >in a way thats easier to understand for a particular person.
    Perhaps the OP could give someone who does frequent this site a chance to explain something in a different way if the first way isn't clear. The most memorable threads I've participated in have involved a lot of back and forth where I've needed to rehash the same concept in many different ways until understanding is reached. It's an extremely productive process for both parties.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    45
    Quote Originally Posted by Prelude View Post
    >Is there a problem with posting the same question on numerous boards?
    It's somewhat rude, to be honest. I see it as akin to getting a second opinion from another doctor before you've even talked to the first doctor. If you're so distrustful of the first doctor, why even bother wasting his time? Now, if you don't get sufficient help from one forum (a rare occurrence if you put any effort into seeking help) it makes sense to try another, but the shotgun approach of firing your question off on multiple forums so you can cherry pick the best initial answer reeks of laziness and disrespect.

    >Perhaps someone who doesn't frequent this site could explain something
    >in a way thats easier to understand for a particular person.
    Perhaps the OP could give someone who does frequent this site a chance to explain something in a different way if the first way isn't clear. The most memorable threads I've participated in have involved a lot of back and forth where I've needed to rehash the same concept in many different ways until understanding is reached. It's an extremely productive process for both parties.

    Perhaps people should learn to be less offended by every little ticky-tack thing. If you have a toothache and you need to find a dentist in short order, you call every darn dentist in the phone book looking for an opening, telling them if a spot opens up to call you. You don't worry about offending the dental office staff because they might cry about you calling other practices.

    From what I read on here daily, many post questions over homework assignments which I imagine have a due date not based on the timetable of the people who could help them and whether or not they either log in or decide to reply.

    Its highly likely you know far more than I do about c++, but there was no help forthcoming from your end...
    Last edited by Incantrix; 10-31-2010 at 12:32 PM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,315
    Quote Originally Posted by Incantrix
    Perhaps people should learn to be less offended by every little ticky-tack thing. If you have a toothache and you need to find a dentist in short order, you call every darn dentist in the phone book looking for an opening, telling them if a spot opens up to call you. You don't worry about offending the dental office staff because they might cry about you calling other practices.
    Bad analogy. Calling several dental clinics to find out which are available is fine: you will stop once you have found one and made your appointment (or in your scenario, you will tell the others that you already have an appointment). What you are doing is calling up several dental clinics, and then booking appointments for all of them to attend to the same dental problem. Since you are only going to see one dentist to get your teeth checked/fixed, you waste the time of the other dentists who leave a spot for you in their busy schedules.

    EDIT:
    Actually, there's more: you don't only waste the time of the other dentists, but you somehow waste their effort as well, as if they attended to you even though you were not present. This is not possible for dentists, of course, so the analogy breaks down, but it is possible for help provided in online communities.
    Last edited by laserlight; 10-31-2010 at 12:46 PM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Perhaps people should learn to be less offended by every little ticky-tack thing.
    You asked why cross-posting might be a problem. There's no need to get snippy if you don't like the answer. Though I'll keep in mind how you treat the people who answer your questions and seriously consider ignoring you next time.

    >Its highly likely you know far more than I do about c++, but there was no help forthcoming from your end...
    I wasn't aware that being knowledgeable somehow obliges me to answer every yahoo who asks a question. This is a volunteer effort, so which threads I choose to offer help in, and my reasons for those choices, is none of your damn business.
    My best code is written with the delete key.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-18-2010, 05:14 AM
  2. Problem Passing Structure Reference To Function
    By soj0mq3 in forum C Programming
    Replies: 9
    Last Post: 04-24-2010, 11:27 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21