lists

hi i have some problem
i wannt to add some functions to my list but i dunno how exacly make it so pleas help me :)

i need:
-reverse list
-save it to binary file
-load from binary file to list
-delete item from list

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <conio.h>
#include <math.h>
#include <time.h>
#include <string>
using namespace std;

using namespace std;

struct lista
{
    int dane;
    struct lista* next;
};


void dodaj (lista* &head, int wartosc) //dodawanie na poczatku listy
{
    lista* el = new lista;
    el->dane = wartosc;
    el->next = head;
    head = el;
}

void dodaj_k(lista *h,int n) {
	lista* nowy;
	while(h->next!=NULL)
		h = h->next;
	nowy = new lista;
	nowy->dane = n;
	nowy->next = NULL;
	h->next = nowy;
}


void pokaz(lista* &head){
	while(head) {
		cout << head->dane << " ";
		head = head->next;
	}
	cout << endl;
}


void mnozenie(lista *h,int ile){
   if(h != NULL)
      while(h != NULL)
      {
         h->dane = h->dane*ile;
         h = h->next;

      }
}

void kwadrat(lista *h){
   if(h != NULL)
      while(h != NULL)
      {
         h->dane *= h->dane;
         h = h->next;

      }
}


int main ()
{
	lista *h = new lista;
				h->dane = 0;
				h->next = NULL;
	//h=NULL;


	int zmienna;
	for(int i=0;i<3;i++){
	cin>>zmienna;
	dodaj_k(h,zmienna);
	}
	//pokaz(h);
	mnozenie(h,4);
	//kwadrat(h);
	pokaz(h);
  
	getch();
    return 0;
}

i need:
-reverse list
-save it to binary file
-load from binary file to list
-delete item from list


I'm pretty shore your "nauczyciel" (teacher) can explain you how to do that.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
std::ostream& operator << (std::ostream &s, schar &x) {
	return s << "Char: " << x.ch << endl << hex << "Char: " << x.ch << endl;
};

std::ostream& operator << (std::ostream &s, sshort &x) {
	return s << "Short 1: " << x.s1  << " Short 2: " << x.s2 << "Short 3: " << x.s3 << "Short 4: " << x.s4 << endl << hex << "Short 1: " << x.s1  << " Short 2: " << x.s2 << "Short 3: " << x.s3 << "Short 4: " << x.s4 << endl;
}

std::ostream& operator << (std::ostream &s, sint &x) {
	return s << "Int 1: " << x.i1  << " Int 2: " << x.i2 << endl << "Hex: " << hex << "Int 1: " << x.i1  << " Int 2: " << x.i2 << endl;
}

std::ostream& operator << (std::ostream &s, sfloat &x) {
	return s << "Float 1: " << x.f1 << " Float 2: " << x.f2 << endl;
}

std::ostream& operator << (std::ostream &s, sdouble &x) {
	return s << "Double 1: " << x.d1 << endl;
}
template<class T>
void matrix_gen(T **t, int n, int m, int x, int y) {
for (int i=0;i<n;i++)
for (int j=0;j<m;j++)
t[i][j] = pick(x, y);
}

template<class T>
void matrix_add(T **tab1, T **tab2, T **tab3, int n, int m) {
for(int i=0;i<n;i++)
for(int j=0;j<m;j++) {
tab3[i][j] = tab2[i][j] + tab1[i][j];
}
}

template<class T> void add_to_list(T x, struct lsz <T> *h) {
struct lsz <T> *nowy;
while(h->next!=NULL)
h = h->next;
nowy = new struct lsz <T>;
nowy->x = x;
nowy->next = NULL;
h->next = nowy;
}

template<class T> int delete_from_list(struct lsz <T> *h, struct lsz <T> *x) {
struct lsz <T> *tmp;
while(h->next != x) {
if(h->next==NULL)
return -1;
h = h->next;
}
tmp = h->next->next;
delete h->next;
h->next = tmp;
}

template<class T> void print_list(struct lsz <float> *h) {
if(h != NULL)
while(h != NULL) {
cout << h->x << endl;
h = h->next;
}
}

template<class T> void print_list(struct lsz <Osoba> *h) {
int i = 1;
while(h != NULL) {
cout << i << ": Imie: "<< h->x.imie << " Nazwisko: " << h->x.nazwisko << " Plec: " << h->x.plec << " Wiek: " << h->x.wiek << endl;
h = h->next;
i++;
}
}

template<class T> void print_list(struct lsz <Student> *h) {
int i = 1;
while(h != NULL) {
cout << i << ": Imie: "<< h->x.imie << " Nazwisko: " << h->x.nazwisko << " Data ur: " << h->x.data_ur << " Nr indeksu: " << h->x.nr_indeksu << endl;
h = h->next;
i++;
}
}
FILE* pl1;
pl1=fopen("naz.txt","rb");
for(int i=0;i<1;i++){
fread(nowe[i].imie,1,sizeof(nowe[i].imie),pl1);
fread(&nowe[i].wiek,1,sizeof(nowe[i].wiek),pl1);
cout<<nowe[i].imie<<endl;}
fclose(pl);
fclose(pl1);

for(int i=0;i<n;i++){

nowe[i].imie=(char*)malloc(sizeof(char));

cin>>nowe[i].imie;
cin>>nowe[i].wiek;
fwrite(nowe[i].imie,1,sizeof(nowe[i].imie),pl);


fstream pl;
pl.open("tab.txt",ios::out);
int n,m;
cin>>n>>m;
int **tab;
tab=new int*[n];
for(int i=0;i<n;i++)
tab[i]=new int[m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
tab[i][j]=(i+1)*(j+1);
pl<<tab[i][j]<<"\t";
}pl<<endl;}
pl.close();
delete tab;

plik.write((char*)nowe[i].imie,sizeof(nowe[i].imie));
plik.write((char*)&nowe[i].wiek,sizeof(nowe[i].wiek));
Topic archived. No new replies allowed.