Skocz do zawartości

Witamy w Nieoficjalnym polskim support'cie AMX Mod X

Witamy w Nieoficjalnym polskim support'cie AMX Mod X, jak w większości społeczności internetowych musisz się zarejestrować aby móc odpowiadać lub zakładać nowe tematy, ale nie bój się to jest prosty proces w którym wymagamy minimalnych informacji.
  • Rozpoczynaj nowe tematy i odpowiedaj na inne
  • Zapisz się do tematów i for, aby otrzymywać automatyczne uaktualnienia
  • Dodawaj wydarzenia do kalendarza społecznościowego
  • Stwórz swój własny profil i zdobywaj nowych znajomych
  • Zdobywaj nowe doświadczenia

Dołączona grafika Dołączona grafika

Guest Message by DevFuse
 

Wklejka drw6b0lvqbwo dodana przez Hleb, 26.03.2013 21:16
Typ:



Lista dwukierunkowa
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.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
 
using namespace std;
 
struct student 
{
	int nr_ID;
	char nazwisko[40];
	char imie[40];
	double punkty;
	struct student *next;
	struct student *prev;
};
 
struct student* wczytaj_wartosci(FILE *plik);
void wypisz_wartosci(student* head);
void dodaj_wartosci(student* point);
void usun_liste(student* head);
struct student* dodaj_nowe_pole();
 
student* head;
int main()
{
	FILE *plik;
 
	char nazwa_pliku[30];
	printf("Pojad nazwe pliku: ");
	scanf("%s", nazwa_pliku);
	printf("Otwieranie plikun");
	if((plik=fopen(nazwa_pliku, "r")) == NULL)
	{
		printf("Plik nie zostal otwartyn");
		exit(1);
	}
	printf("Otwarto plikn");
	head = wczytaj_wartosci(plik);
	wypisz_wartosci(head);
	int sterowanie;
	printf("Chcesz dodac studenta??n0-NIEn1-TAKn");
	scanf("%i", &sterowanie);
	while(sterowanie)
	{
		dodaj_wartosci(dodaj_nowe_pole());
		printf("Chcesz usunac studenta??n0-NIEn1-TAKn");
		scanf("%i", &sterowanie);
	}
	wypisz_wartosci(head);
	usun_liste(head);
 
	return 0;
}
 
struct student* wczytaj_wartosci(FILE *plik)
{
	student* wsk, *head = NULL;
	while(!feof(plik))
	{
		if(head==NULL)
		{
			head=(student*)malloc(sizeof(student));
			head->next=NULL;
			head->prev=NULL;
			fscanf(plik, "%i %s %s %lfn", &head->nr_ID, head->nazwisko, head->imie, &head->punkty);
			wsk=head;
		}
		else
		{
			wsk->next=(student*)malloc(sizeof(student));
			wsk->next->prev = wsk;
			wsk=wsk->next;
			wsk->next=NULL;
			fscanf(plik, "%i %s %s %lfn", &wsk->nr_ID, wsk->nazwisko, wsk->imie, &wsk->punkty);
		}
	}
	return head;
}
struct student* dodaj_nowe_pole()
{
	student *wsk = (student*)malloc(sizeof(student));
	printf("Podaj ID studenta: ");
	scanf("%i", &(wsk->nr_ID));
	printf("Podaj Nazwisko studenta: ");
	scanf("%s", wsk->nazwisko);
	printf("Podaj Imie silnika: ");
	scanf("%s", wsk->imie);
	printf("Podaj Liczbe punktow studenta: ");
	scanf("%lf", &(wsk->punkty));
	wsk->next = NULL;
	wsk->prev = NULL;
	return wsk;
}
void wypisz_wartosci(student* head)
{
	student *wsk, *pom;
	printf("nWypisuje elementy listy:n");
	wsk=head;
	if(head->next == NULL)
	{
		printf("t%it%st%st%.1lfn", head->nr_ID, head->nazwisko, head->imie, head->punkty);
		return;
	}
	else
	{	
		while(wsk!=NULL)
		{
			printf("t%it%st%st%.1lfn", wsk->nr_ID, wsk->nazwisko, wsk->imie, wsk->punkty);
			wsk=wsk->next;
			if(wsk->next==NULL)
			{		
				printf("t%it%st%st%.1lfn", wsk->nr_ID, wsk->nazwisko, wsk->imie, wsk->punkty);
				break;
			}
		}
 
	}
}
void usun_liste(student* head)
{
	student *wsk=head;
	while(wsk->next != NULL)
	{
		wsk=wsk->next;
		free(wsk->prev);
		wsk->prev=NULL;
	}
	free(wsk);
}
void dodaj_wartosci(student *point)
{
	student *wsk;	
	if(head == NULL)
	{
		head=point;
	}
	if(head->nr_ID > point->nr_ID) 
	{
		point->next = head;
		head->prev = point;
	}
	else
	{
		wsk=head;
		while(wsk->next->nr_ID <= point->nr_ID)
		{
			if(wsk->next->nr_ID == point->nr_ID)
			{
				printf("Student o podanym ID ISTNIEJEn");
				free(point);
				return;
			}
			else
			{
				wsk = wsk->next;
				if(wsk->next==NULL)
				{
					wsk->next = point;
					point->prev = wsk;
					wsk=wsk->next;
 
					wsk->next=NULL;
						return;
				}
			}
		}
		point->next = wsk->next;
		wsk->next = point;
		point->prev = wsk;
		point->next->prev=point;
	}
}

Dodanych wklejek: 12215
Powered By (Pav32) Pastebin © 2011