programming etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
programming etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

22 Ağustos 2015 Cumartesi

Determining The Largest Word In A String C++

#include
#include
using namespace std;

int main(){
//initialize the variables
string str;
int endword,arraysize;
int maxword=0;
int counter=0;
//getline command getting all line including spaces...
getline(cin,str);
//array size
arraysize = str.length();
//adding one "space" character at the end of string array for ending the procedure
str[arraysize+1]=' ';
//for loop will determine the longest character number
for(int i=0; i
if(str[i]!= ' '){

counter++;

}
else if(str[i] == ' '){
//once we have the whole world, compares the longest character number with the next one
if(counter>maxword){
maxword = counter;
//this is going to be used for counting characters in order to output the whole longest word
endword=i;

}

counter = 0;
}

}
//with the help of "endword" the location of characters which
//the longest word does have were known && we can get all characters together
for(int i=endword-maxword;i<=endword;i++)
cout< cout<<" the length is "< }


10 Kasım 2013 Pazar

Some tiny codes in C# ( Form Application )

    I know it's been a long time , but i'm back.Today i am going to put some codes in C# , i don't like it though.Do not expect so much  things from these codes because these two coding were little homework in my Data Structures class so they simply sort the numbers that you put on the text field, and one button to run these codes and ofcourse the other text field to show the ordered-numbers.I used "selectionsort" and "bubble sort" algorithms.I hope , beginners of C# can get inpiration by looking at these codes.

Insertion Sort C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sorting.examples
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
            string text = textBox1.Text;
            string[] words = text.Split(delimiterChars);
            int[] intValues = new int[words.Length];

            for (int i = 0; i < words.Length; i++)
            {
                intValues[i] = Convert.ToInt32(words[i]);
            }
            int j,temp;
            
            for ( j = 1; j < intValues.Length; j++) {

                for (int i = 0; i < intValues.Length-j; i++)
                {
              if (intValues[i] > intValues[i + 1])
                    {
                        temp = intValues[i + 1];
                        intValues[i + 1] = intValues[i];
                        intValues[i] = temp;
                    }
                }
            }
            var result = string.Join(",", intValues);
            textBox2.Text = result;
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {  
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
        } 
    }
}
Bubble Sort C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sorting.examples
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
            string text = textBox1.Text;
            string[] words = text.Split(delimiterChars);
            int[] intValues = new int[words.Length];

            for (int i = 0; i < words.Length; i++)
            {

                intValues[i] = Convert.ToInt32(words[i]);

            }

            int j,temp;
            
            for ( j = 1; j < intValues.Length; j++) {

                for (int i = 0; i < intValues.Length-j; i++)
                {


                    if (intValues[i] > intValues[i + 1])
                    {
                        temp = intValues[i + 1];
                        intValues[i + 1] = intValues[i];
                        intValues[i] = temp;
                    }
                }
            }

            var result = string.Join(",", intValues);
            textBox2.Text = result;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

       
    }
}