Create a program that:

  • provides the initial input of integers and forms from them an ordered list;
  • then remove negative numbers from the list and double the positive ones;
  • the original and converted list should be displayed;

I myself have performed only the first item and then not completely, because I do not know how to arrange

#include "stdafx.h" #include <iostream> using namespace std; #define list struct spisok list {int info; list* next; }; list* head; list* first(int d) {list *t=new list; t->next=0; t->info=d; return t; }; void insert (list** s, int x) { list* t=*s; list* p=0; list *r; while(t!=0) { p=t; t=t->next; } r=first(x); if(p==0) *s=r; else p->next=r; }; void display(list *s) { list *t=s; while(t) { cout<<t->info; t=t->next; } }; int _tmain(int argc, _TCHAR* argv[]) {int x; cout<<"Vvedite 4isla"<<endl; cin>>x; head=first(x); do {cin>>x; insert(& head,x); } while(x!=0); display(head); return 0; } 
  • for the second item: go through the list (you know how?), test the value of the element and either modify it (for positive), or delete (for negative). You will need to delete from the list. - VladD
  • So I just do not know how to go through the list. probably through while ()? I also do not know how to delete the delete function. - SS7
  • aha, for example, through while. The removal function is something you yourself, these are the basics. ask your teacher, eventually. - VladD
  • Yes, the fact of the matter is that the teacher is not very good caught. we generally have one lecture in two weeks and the material is very compressed, but in practice the teacher is almost always absent. If not difficult, please tell me a good literature for beginners - SS7
  • @ SS7, insert you obviously wrong. There all the same it would be necessary to compare the elements of the list with the new one and insert it in the right place. As a result, get an ordered list. - I would change the prototype of insert () and everything will become simple. list * insert (list * head, list * newitem); Then data entry and list building looks like this: list * head = 0, * item; while (item = get_item ()) head = insert (head, item); Starting insert is trivially list * insert (list * head, list * item) {if (! Head) return item; ...} See how everything is simplified. Next yourself. - avp


0