void createArray(int la[], int n){
int i, d;
for (i=0;i<n;i++){
if(i<1)
scanf("%d", &la[i]);
else{
scanf("%d", &la[i]);
for(d=1;d<i+1;d++){
if(la[i]==la[i-d]){
printf("The number you entered is already in the list. Enter another no.: ");
i--;}}
}
}
}
void printArray(int la[],int n){
int i;
for (i=0;i<n;i++){
printf("%d ", la[i]);
}
}
int inserAtPos(int la[], int n, int item, int k){
int i, w,c;
for(i=1;i>0;i++){
if(contains(la,item,n)==1){
printf("The number you want to insert is already in the list. Enter another no.: ");
scanf("%d", &item);
}
else{
c=n;
for(w=k; w<(n+1); w++){
la[c]=la[c-1];
c--;
}
la[k-1]=item;
break;
}
}
return 1;
}
int contains(int la[], int item, int n){
int i, found=0;
for(i=0;i<n;i++){
if(la[i]==item){
found=1;
break;
}}
return found;
}
void insertFront(int la[], int n,int item ){
int i, w, c;
for(i=1;i>0;i++){
if(contains(la,item,n)==1){
printf("The number you want to insert is already in the list. Enter another no.: ");
scanf("%d", &item);
}
else{
c=n;
for(w=(n+1); w>1; w--){
la[c]=la[c-1];
c--;
}
la[0]=item;
break;
}
}
}
void removeAtPos(int la[], int n, int index){
int d, i;
i=index;
for(d=(i-1);d<n-1;d++){
la[index-1]=la[index];
index++;
}
}
int removeItem(int la[], int n, int item){
int d, c, f, remove=1;
if(contains(la,item,n)==0){
remove=-1;
}
else{
for(d=0;d<n;d++){
if(item==la[d]){
c=d;
for(f=(c);f<n-1;f++){
la[d]=la[d+1];
d++;
}
break;
}
}}
return remove;
}
int removeFront(int la[], int n){
int i;
for(i=0;i<n;i++){
la[i]=la[i+1];
}
return 1;
}
void locateIndex(int la[],int n, int item){
int d, i, g, f;
while(f=1){
for(i=0;i<n;i++){
if(item==la[i])
g=1;
f=2;
}
if(g==1){
for(d=0;d<n;d++){
if(item==la[d]){
printf("The item is at position %d.", d+1);
}
}
break;
}
else{
printf("Item is not in the list.");
printf("\nEnter another number: ");
scanf("%d", &item);
f=1;
}}
}
void sortAscending(int la[], int n){
int i, temp, b;
for(i=0;i<n;i++){
for(b=0;b<(n-(i+1));b++){
if (la[b]>la[b+1]){
temp=la[b];
la[b]=la[b+1];
la[b+1]=temp;
}}}
printf("Sorting successful!");
printf("\nARRAY list in ASCENDING order : ");
printArray(la, n);
}
void sortDescending(int la[],int n){
int i, temp, b;
for(i=0;i<n;i++){
for(b=0;b<(n-(i+1));b++){
if (la[b]<la[b+1]){
temp=la[b];
la[b]=la[b+1];
la[b+1]=temp;
}}}
printf("\nARRAY list in DESCENDING order : ");
printArray(la, n);
}
void locateItem(int la[],int n, int item){
int i;
for(i=0;i<n;i++){
if(item==la[i]){
printf("Its in the list!");
break;
}
else{
printf("Not in the list!");
break;
}
}
}
About this blog
These codes here are just based on my own knowledge learned from my IT subjects. I know there are more ways that this draft codes can be enhance, so..
Please feel free to comment & suggest.. Suggest Codes which makes my existing codes simpler.. Thanks!
Archives
Categories
Making Life Simple w/ Programming
Links
- w3schools.com
- Java & Textpad Setup Guide 2
- Java & Textpad Setup Guide
- ASCII Alphabet Characters
- File Handling - Forum
- File Handling - Tutorial 0.1
- File Handling - Tutorial 0.2
- Bin-Dec Conversion - Forum
- Use of getch(), getche(), & getchar()
- The C Book
- SEO
- Common C programming errors
- Tutorial - Array Functions
- August Council Tutorial - c
- C language tutorials
- cprogramminglanuage.net
0 comments