Главная »
2018 » Апрель » 20 » Списки. Создание и вывод
10:46 Списки. Создание и вывод |
#include <iostream>
using namespace std;
struct elem
{
int info;
elem *next;
};
elem *insert_begin(elem *ptr, int a);
void print(elem *ptr);
int main()
{
setlocale(LC_ALL, "Russian");
elem *head=NULL;
head=insert_begin(head, 10);
head=insert_begin(head, 20);
head=insert_begin(head, 30);
print(head);
system("pause");
return 0;
}
elem *insert_begin(elem *ptr, int a)
{
elem *temp;
temp=new elem;
temp->info=a;
temp->next=ptr;
return temp;
}
void print(elem *ptr)
{
elem *temp;
temp=ptr;
while (temp!=NULL)
{
cout<<temp->info<<" ";
temp=temp->next;
}
cout<<endl;
}
|
Просмотров: 278 |
Добавил: denjes
| Рейтинг: 0.0/0 |