| | |
help!shell sort, deck...
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 29
Reputation:
Solved Threads: 0
hello,can someone help me?
I must make a program which contains:
Deck (the data in it must be integer(numbers)),(if possible,in header file).
Sort the elements by the method of Shell
Find the elements that can be divided by 5, and smaller then the largest number that can be divided by 7.
The results(if possible in header file).
Function main() with menu of the functions, and checking the status of the data.
I understand this well,but I can't do it. I've tried so long and I just can't.
You are my last hope.
Thanks
[code]
I must make a program which contains:
Deck (the data in it must be integer(numbers)),(if possible,in header file).
Sort the elements by the method of Shell
Find the elements that can be divided by 5, and smaller then the largest number that can be divided by 7.
The results(if possible in header file).
Function main() with menu of the functions, and checking the status of the data.
I understand this well,but I can't do it. I've tried so long and I just can't.
You are my last hope.
Thanks
[code]
C Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> void push_l(int n); void push_r(int n); void shellsort(int a[];int left;int right); struct deck1{ int key; deck1*next; } *left=NULL; *right=NULL; void main(){ int num; do{ int numb; cout<<"Menu:\n"; cout<<"1-Add elements(left)\n"; cout<<"2-Add elemens(right)\n"; cout<<"3-Find elements\n"; cout<<"4-Sort\n"; cout<<"5-Results\n"; cout<<"6-End\n"; cout<<"Select:"; cin<<num; switch(num){ case(1): case(2): out<<"Add elements:"; cin>>numb; if(num 1) push_l(numb); else push_r(numb); break; case(3):{ if(numb%5&&numb<(i don't know how to do this) cout<<numb<<"\n"; getche(); } else{ cout<<"There's no such number!\n"; getch(); } break; case(4): cout<<numb.shelsort()<<"\n"; break; case(5): cout<<numb<<\n; while(num!6); break; } void push_l(int n){ deck1 *p; p=left; left=new deck1; left->key=n; left->next*p; if(right==NULL){ right=left;} } void push_r(int n){ deck1*p; p=right; right=new elem; right->key=n; right->next=NULL; if(left==NULL) left=right; else p->next=right; } void shellsort(int a[];int left;int right){ int h; for(h=1;h<=(right-left)/9; h=3*h+1; for(;h>0;h/=3) for(int i=left+h;i<=right;i++){ int j=i; int v=a[i]; while(j)=left+h&&v<a[j-h]){ a[j]=a[j-h]; j-=h;} a[j]=v; } }}}
What is line 10, and 11?
main() must be able to return zero, and there really is no file called <iostream.h>, look it up.
Is getche() a typo, or do you really need it?
Biggest question: is your tab, or space bar broken? You'll never be able to fix something no-one can read, I just stop after several lines, and scrolled through the mess.
main() must be able to return zero, and there really is no file called <iostream.h>, look it up.
Is getche() a typo, or do you really need it?
Biggest question: is your tab, or space bar broken? You'll never be able to fix something no-one can read, I just stop after several lines, and scrolled through the mess.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
•
•
Join Date: Apr 2008
Posts: 29
Reputation:
Solved Threads: 0
I''m so sorry about the mess!
I hope this is better:
line 10 and 11 are the sides of the deck (left and right ). I made them NULL so I can add elements later.
I hope this is better:
C Syntax (Toggle Plain Text)
#include<stdafx.h> #include<iostream.h> #include<conio.h> void push_l(int n); void push_r(int n); void shellsort(int a[];int left;int right); struct elem{ int key; elem *next; } *left=NULL; *right=NULL; int main(){ int num; do{ int numb; cout<<"Menu:\n"; cout<<"1-Add elements(left)\n"; cout<<"2-Add elemens(right)\n"; cout<<"3-Find elements\n"; cout<<"4-Sort\n"; cout<<"5-Results\n"; cout<<"6-End\n"; cout<<"Select:"; cin<<num; switch(num){ case(1): case(2): cout<<"Add elements:"; cin>>numb; if(num 1) push_l(numb); else push_r(numb); break; case(3):{ if(numb%5&&numb<(i don't know how to do smaller from divided by 7) cout<<numb<<"\n"; } else{ cout<<"There's no such number!\n"; } break; case(4): cout<<numb.shelsort()<<"\n"; break; case(5): cout<<numb<<\n; while(num!6); break; } void push_l(int n){ elem *p; p=left; left=new elem; left->key=n; left->next*p; if(right==NULL){ right=left;} } void push_r(int n){ elem *p; p=right; right=new elem; right->key=n; right->next=NULL; if(left==NULL; left=right; else p->next=right; } void shellsort(int a[];int left;int right){ int h; for(h=1;h<=(right-left)/9; h=3*h+1; for(;h>0;h/=3) for(int i=left+h;i<=right;i++){ int j=i; int v=a[i]; while(j)=left+h&&v<a[j-h]){ a[j]=a[j-h]; j-=h; } a[j]=v; } } } }
Last edited by didi00; Dec 5th, 2008 at 7:15 pm.
Have you you tried compiling it, and reading the error reports? There's invalid operations, spelling mistakes, missing types, definitions where there shouldn't be, et al.
I think you need to start anew, slowly adding piece-by-piece, compiling, fixing, learning, and so on.
You also might want an IDE to help do the indenting for you, as you go along.
I think you need to start anew, slowly adding piece-by-piece, compiling, fixing, learning, and so on.
You also might want an IDE to help do the indenting for you, as you go along.
Last edited by MosaicFuneral; Dec 5th, 2008 at 8:38 pm.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
•
•
Join Date: Apr 2008
Posts: 29
Reputation:
Solved Threads: 0
Actually, I find out why it was giving me no errors, I've worked over it and now I have some questions:
The shell sort will work only if I "place" the deck into massive. (I don't know how), and I don't know will be good to find the max number then to divide it with 7 and than to add something like:
num%&&num<max%7 (I'm talking about case 3), or there is some easy way to do it?
I'm having progress so far
Thanx
The shell sort will work only if I "place" the deck into massive. (I don't know how), and I don't know will be good to find the max number then to divide it with 7 and than to add something like:
num%&&num<max%7 (I'm talking about case 3), or there is some easy way to do it?
I'm having progress so far
Thanx
Last edited by didi00; Dec 6th, 2008 at 4:43 pm.
•
•
Join Date: Apr 2008
Posts: 29
Reputation:
Solved Threads: 0
Ok, I was able to correct most of the code, but I still have 10 errors.
Can someone help me now?
Thanks
Can someone help me now?
C Syntax (Toggle Plain Text)
#include<fstream.h> #include<iostream.h> #include<conio.h> void push_l(int n); void push_r(int n); int pop_l(int n); int pop_r(int n); void shell_sort(int a[],int size); void results(); struct elem{ int key; elem*next; }; elem *left=NULL; elem *right=NULL; int b[100]; int sort; void main(){ int num; do{ int numb; cout<<"Menu:n"; cout<<"1-Add elements(left)\n"; cout<<"2-Add elemens(right)\n"; cout<<"3-Adding into array\n"; cout<<"4-Find elements\n"; cout<<"5-Sort\n"; cout<<"6-Results\n"; cout<<"7-End\n"; cout<<"Select:\n"; cin>>num; switch(num){ case(1): cout<<"Add elements to left:"; while(cin>>numb){ push_l(numb); } break; case(2): cout<<"Add elements to right:"; while(cin>>numb){ push_r(numb); } break; case(3): int k,j,i=0; int a[100]; a[0]=1; while(left){ pop_l(k); a[i]=k; i++; } for(j=0;j<=i;j++){ pop_r(a[j]); } break; case(4): int broj; int counter=-1; for (i=0; i<100; i++) if (a[i]%7==0) broj=a[i]; for (i=0; i<numb; i++) if (a[i]<=broj) if (a[i]%5==0) { counter=counter++; b[counter]=a[i]; } else cout<<"There's no such number!\n"; } break; case(5): cout<<sort=shell_sort(numb); break; case(6): ifstream f("results.txt"); while(pop_l(numb)&&pop_r(numb)){ cout<<numb<<""; } while(num!=7); break; } void push_l(int n){ elem *p=left; left=new elem; left->key=n; left->next=p; if(p==right) right=left; } void push_r(int n){ elem *p=right; right=new elem; right->key=n; right->next=NULL; if(p) p->next=right; if(left==p) left=right; } int pop_l(int &n){ elem *p; if(left){ n=left->key; p=left; left=left->next; if(left==NULL) right=NULL; delete p; return 1; } else return 0; } int pop_r(int &n){ elem *p; if(right){ n=right->key; if(left==right){ delete right; left=right=NULL; } else{ p=left; while(p->next!=right) p++; n=right->key; p->next=NULL; delete right; right p; return 1; } else return 0; } void shell_sort(int a[],int size){ int i,j,increment,temp; increment=size/2; while (increment>0) { for(i=increment;i<size;i++){ j=i; temp=a[i]; while((j>=increment)&&(a[j-increment]>temp)){ a[j]=a[j-increment]; j=j-increment; } a[j]=temp; } if(increment==2) increment=1; else increment=(int)(increment/2.2); } } } }
Last edited by didi00; Dec 10th, 2008 at 4:59 pm.
![]() |
Other Threads in the C Forum
- Previous Thread: Need help with initializing items in linked list in a new way
- Next Thread: Please do corrections in my code to get the desired result
| Thread Tools | Search this Thread |
#include adobe api array arrays asterisks binarysearch calculate char cm copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic feet fflush fgets file fork forloop framework frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o include incrementoperators input interest kernel kilometer linked linkedlist linux linuxsegmentationfault list lists locate logical_drives loopinsideloop. match matrix meter microsoft motherboard mqqueue multi mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming pyramidusingturboccodes radix read recursion recv repetition research scanf scheduling scripting segmentationfault sequential shape socket socketprograming stack standard string strings systemcall testing turboc unix user voidmain() wab windows.h






