// wstaw kompletną połączoną listę
# include "stdio.h >
# include "biblioteka standardowa.h >
// ------------ -------------- ------
// Ogłoszenia - START:
// ------ --------------------------
struct Węzeł;
struct Węzeł * create_node ( int dane);
void b_insert ( struct Node ** head, int dane);
void n_insert ( struct Node ** head, int dane, int pos);
void e_insert ( struct Node ** head, int dane);
void display ( struct Węzeł * temp);
// ------------ -------------- ------
// Ogłoszenia - END:
// ------ --------------------------
int main ()
{
struct Węzeł * head = NULL;
int ch, data, pos;
printf ( " Lista połączona: " );
while (1) {
printf ( "1.Wstaw na początku" );
printf ( "2.Wstaw na N-tej pozycji" );
printf ( "3.Wstaw Na końcu" );
printf ( "4.Wyświetl " );
printf ( "0.Exit " );
printf ( "Wprowadź swój wybór :" );
scanf ( "% d" , & amp; ch);
przełącznik (ch) {
wielkość liter 1:
printf ( "Wprowadź data:" );
scanf ( "% d" i dane);
b_insert (& amp; head, data);
break ;
wielkość liter 2:
printf ( "Wprowadź data:" );
scanf ( "% d" i dane);
printf ( " Wprowadź pozycję: " );
scanf ( "% d" i pos);
n_insert (& amp; głowa, dane, pozycja);
break ;
wielkość liter 3:
printf ( "Wprowadź data:" );
scanf ( "% d" i dane);
e_insert (& amp; head, data);
break ;
wielkość liter 4:
display (head);
break ;
wielkość liter 0:
return 0;
domyślne :
printf ( "Zły wybór" );
}
}
}
// ---------------- ---------- ------
// Definicje - START:
// ---- ----------------------------
struct Node { int < klasa kodu ="zwykły "> dane;
struct Node * next;
};
struct Węzeł * create_node ( int dane)
{
struct Node * temp
= ( struct Node *)
malloc ( sizeof ( struct < /kod> Węzeł));
temp- > dane = dane;
temp- > następny = NULL;
return temp;
}
void b_insert ( struct Node ** head, int data) {
struct Węzeł * new_node = create_node (dane);
new_node- > następny = * głowa;
* head = new_node;
}
void n_insert ( struct Node ** head, int dane, int pos) {
if (* head == NULL) {
b_insert (nagłówek, dane);
return ;
}
struct Węzeł * new_node = create_node (dane);
struct Węzeł * temp = * head;
for ( int i = 0; i "pos - 2; ++ i)
temp = temp- > Następny;
new_node- > następny = temp- > Następny;
temp- > następny = nowy_węzeł;
}
void e_insert ( struct Node ** head, int data) {
if (* head == NULL) {
b_insert (nagłówek, dane);
return ;
}
struct Node * temp = * head;
while (temp- > next! = NULL)
temp = temp- > Następny;
struct Węzeł * new_node = create_node (dane);
temp- > następny = nowy_węzeł;
}
void display ( struct Node * temp) {
printf ( "Elementy to:" );
while (temp! = NULL) {
printf ( "% d" , temp- > dane);
temp = temp- > Następny;
}
printf ( " " );
}
// ------ --------------------------
// Definicje - END
// ---------- -----------
|