473,769 Members | 3,820 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need hlep to delete array only because all function is ok (inser, sort andsearch)

14 New Member
Need hlep to delete array only because all function is ok (inser, sort andsearch)


#include <iostream.h>

//functions prototype
void Insert(int[],int);
void Delete(int[],int);
int Search(int[],int);
void Sort(int[],int);

int n=0,i=0,locatio n;
bool found;

//main
int main()
{

int grades[10],i,g;
for(i=0;i<4;i++ ){
cout<<"Enter a new grade ";
cin>>g;
Insert(grades,g );
//cout <<"grades["<<i<<"]="<<grades[i]<<endl;
} // end for loop

// functions definitions
Sort(grades,n);

//print out the values of the array
for(i=0;i<4;i++ ){
cout <<grades[i]<<endl;

}
Delete(grades,3 );

/* for(i=0;i<3;i++ ){
cout <<grades[i]<<endl;

}
*/
return 0;
} // end main

// functions
void Insert(int a[],int item){
a[n]=item;
n++;
}

void Delete (int a[],int item){
Search(a,item);
if (found==true){
cout <<" out of search, found in place"<<locatio n<<endl;
for (int k=location;k=3; k++){ //////here is to check//////
a[k]=a[k+1];
}
}
else
cout <<"not found!!";


}// end delete

int Search(int a[],int item){
// Assumption: Whenever it finds the value, it stops
for (int i=0;i<n;i++){
if (a[i]==item){
found=true;
cout <<"inside seearch,found in place "<<i<<endl;
location= i;
return location;
}
else
found=false;

}
}//end of search

void Sort(int a[], int length)
{
int count,SI, MI,temp;
for(count = 0;count<length-1;count++)
{
MI = count;
for(SI = count + 1; SI <length; SI++)
if(a[SI] < a[MI]) MI = SI;

// swap the grades
temp = a[MI];
a[MI] = a[count];
a[count] = temp;
}

} // end of sort
Nov 11 '06 #1
1 1592
horace1
1,510 Recognized Expert Top Contributor
the removal of the element at location in delete() was faulty, try
Expand|Select|Wrap|Line Numbers
  1. void Delete (int a[],int item){
  2. Search(a,item);
  3. if (found==true){
  4. cout <<" out of search, found in place"<<location<<endl;
  5. for (int k=location;k+1<n;k++){ //////here is to check//////
  6. a[k]=a[k+1];
  7. }
  8. n=n-1;
  9. }
  10. else
  11. cout <<"not found!!";
  12. }// end delete
  13.  
Nov 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4018
by: Christopher Jeris | last post by:
I am relatively new to JavaScript, though not to programming, and I'm having trouble finding the idiomatic JS solution to the following problem. I have a table with (say) fields f1, f2, f3. I do a database query and what I wind up with is a structure Q of arrays: Q.f1 is field f1 in row n, Q.f1.length == Q.f2.length == Q.f3.length is the record count of the query. (This representation is of course backwards, but that's what...
7
6495
by: lkrubner | last post by:
The PHP scripting language has the array_unique() function that gets the unique, non-redundant values out of an array. Does Javascript have anything similar?
3
2476
by: ritchie | last post by:
Hi all! Still working on this program! Just to recap, I am writing a program to sort an array with four different sort algorythms. I am having a little trouble at the moment though! Now, I am trying to calculate, with each sort, how many times during the sort the array elements are compared and swapped.
5
3790
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public List<RoleData> GetRoles() { return GetRoles(null, false); }
24
3461
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have declared an array as: char *stringArray = {"one","two","three","a"}; When I pass the array using:
20
4649
by: Martin Jørgensen | last post by:
Hi, I'm reading a number of double values from a file. It's a 2D-array: 1 2 3 4 5 6 7 ------------- 1 3.2 2 0 2.1 3 9.3 4
6
6430
by: flash | last post by:
write a program that manipulates arrays of integers. The main program should call three functions: Insert, Delete, and Search. The Insert function should call a function Sort that sorts the array. Here is a description of the three functions: Insert: Accepts as input the array and the element you want to insert into the array. The function should insert the element at the end of the array and should call the function Sort to sort the...
3
2200
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it both on the file system and in a mySql database. 90% of the time it works just fine. But for some reason, with some photos, it doesn't work. The image never shows up on the filesystem and there is no entry in the database. I feel it's a problem...
4
1581
by: Paul David Buchan | last post by:
Hello, I'm attempting to write a program to read in database files (.dbf). When I do it all as a single procedure in main, everything works. However, what I really want, is to pass the database filename to a function, and have it pass back an array containing the database contents, and some parameters telling me the dimensions of the array. I've succeeded in getting my function to read in the dbf file, and it returns the dimensions of...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7401
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.