0% found this document useful (0 votes)
7 views

Neagu Teodor 9E Liceul Pedagogic Constantin Bratescu

The document discusses vectors and their structure. Vectors are characterized by their type and number of elements. The document describes how to define a vector in code, input elements into a vector, and output the elements of a vector. It also lists two common sorting methods for vectors: bubble sort and insertion sort. Code examples are provided to implement bubble sort and read/write vectors to files.

Uploaded by

Teodor Neagu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Neagu Teodor 9E Liceul Pedagogic Constantin Bratescu

The document discusses vectors and their structure. Vectors are characterized by their type and number of elements. The document describes how to define a vector in code, input elements into a vector, and output the elements of a vector. It also lists two common sorting methods for vectors: bubble sort and insertion sort. Code examples are provided to implement bubble sort and read/write vectors to files.

Uploaded by

Teodor Neagu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

VECTORI

Neagu Teodor 9E Liceul Pedagogic Constantin Bratescu

Vectorul

Structura unui vector: - sir de date de acelasi tip Caracterizat prin: -tip -numar de elemente

Structura: include<iostream.h> void main() { int n,x[100]; cout<<n=;cin>>n; for(int i=0; i<n ; i++) {cout<<x[<<i<<]=; cin>>x[i];}

Structura:

for(i=0;i<n;i++) cout<<x[i]<<,; cout<<\b ;

Tipuri

de sortare: - sortare prin metoda bulelor - sortare prin insertie

#include<fstream.h> void main() {int vb; do{vb=1; for(i=0;i<p-1; i++) if( c[i]>c[i+1]) {aux=c[i]; c[i]<c[i+1]; c[i+1]<aux; vb=0;} }while(vb==0); }

include<ifstream.h> void main() { int n,a[100],b[100], i, j; Ifstream f(vector.in); f>>n; for(i=0;i<n;i++) f>>a[i]; for(i=0;i<n;i++) {j=0; while(i<j && b[j]<a[i]) j++; for(int k; k=i-1; k>=j; k--) b[k+1]=b[k]; b[j]=a[i];} for(i=0;i<n;i++) cout<<b[i]<<,; }

You might also like